英文:
Does not work isset post in dynamically created submit
问题
我有PHP文件中的代码:
<form id="form_id" action="" method="post">
<?php if (isset($_POST["123"])) {echo "BUTTON WORKS";}?>
</form>
<script src="file.js"></script>
我有JS文件中的代码:
let testButton = document.createElement("submit");
testButton.innerHTML = "Click it";
document.getElementById("form_id").appendChild(testButton);
testButton.name = "123";
PHP代码不起作用。为什么?
英文:
I have code in PHP file:
<form id="form_id" action="" method="post">
<?php if (isset($_POST["123"])) {echo "BUTTON WORKS";}?>
</form>
<script src="file.js"></script>
And I have code in JS file:
let testButton = document.createElement("submit");
testButton.innerHTML = "Click it";
document.getElementById ("form_id").appendChild(testButton);
testButton.name = "123";
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
let testButton = document.createElement("button"); /*HERE*/
testButton.innerHTML = "Click it";
document.getElementById ("form_id").appendChild(testButton);
testButton.name = "123";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论