我在PHP中有一个循环表单,我想通过javascript提交。问题是,每个ID似乎都需要他们自己的单独的JavaScript提交代码。set javascript div id to increasing var
PHP代码:
$i = 0;
while ($i < $num) {
$j = $i + 1;
echo "<form id='form".$j."' name='form3' method='post' action='post.php'>
<input type ='checkbox' name='box1' value = 'useless' > Useless</input>
<input type='submit' name= 'submit' id='submit' value='Submit' />
</form>";
$i++;
}
的Javascript不工作:
var x = 2;
var y = '<?php echo $num; ?>';
while (x <= y) {
$(document).ready(function() {
$("#form" + x).on("change", "input:checkbox", function() {
$("#form" + x).submit();
});
});
x++;
你需要增加你的while循环中的X,如果控制台日志这是是一个无限循环,但在相同的元素。 – David
php在js中?你怎么称呼js功能?什么样的预期结果?你目前的结果是什么? –