不起作用,动态创建的提交中没有设置 post

huangapple go评论102阅读模式
英文:

Does not work isset post in dynamically created submit

问题

我有PHP文件中的代码:

  1. <form id="form_id" action="" method="post">
  2. <?php if (isset($_POST["123"])) {echo "BUTTON WORKS";}?>
  3. </form>
  4. <script src="file.js"></script>

我有JS文件中的代码:

  1. let testButton = document.createElement("submit");
  2. testButton.innerHTML = "Click it";
  3. document.getElementById("form_id").appendChild(testButton);
  4. testButton.name = "123";

PHP代码不起作用。为什么?

英文:

I have code in PHP file:

  1. &lt;form id=&quot;form_id&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
  2. &lt;?php if (isset($_POST[&quot;123&quot;])) {echo &quot;BUTTON WORKS&quot;;}?&gt;
  3. &lt;/form&gt;
  4. &lt;script src=&quot;file.js&quot;&gt;&lt;/script&gt;

And I have code in JS file:

  1. let testButton = document.createElement(&quot;submit&quot;);
  2. testButton.innerHTML = &quot;Click it&quot;;
  3. document.getElementById (&quot;form_id&quot;).appendChild(testButton);
  4. testButton.name = &quot;123&quot;;

php code does not work. Why?

答案1

得分: 2

Create a button element not submit like this one

let testButton = document.createElement("button"); /HERE/
testButton.innerHTML = "Click it";
document.getElementById("form_id").appendChild(testButton);
testButton.name = "123";

英文:

Create a button element not submit like this one

  1. let testButton = document.createElement(&quot;button&quot;); /*HERE*/
  2. testButton.innerHTML = &quot;Click it&quot;;
  3. document.getElementById (&quot;form_id&quot;).appendChild(testButton);
  4. testButton.name = &quot;123&quot;;

huangapple
  • 本文由 发表于 2023年6月12日 21:50:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定