我有2个表格。当我提交frm1时,我有一些检查选项并使用变量checkedValues来存储它。循环并提交表格jquery
我在每个选中的选项中循环,将值更改为frm2,提交并在3秒后打开弹出窗口。但它不适用于提交表单2和setTimeout函数。
有没有人有任何想法来解决这个问题?
<form action="" method="post" name='frm1'>
<input type="checkbox" name="1" id="1" value="1" class="checkbox">
<input type="checkbox" name="2" id="2" value="1" class="checkbox">
<input type="checkbox" name="3" id="3" value="0" class="checkbox">
<input type="checkbox" name="4" id="4" value="0" class="checkbox">
<input type="submit" value='add'>
</form>
<form action='http://example.com' method='post' name='frm2' target="_blank">
<input type="text" name="fname" class="form-control" value=''>
<input type="text" name="fvalue"class="form-control" value=''>
</form>
<script>
$('#add').click(function(){
var store= <?php echo json_encode($store)?>;
var checkedValues = $('input:checkbox:checked').map(function() {
return this.id;
}).get();
$.each(checkedValues, function(index,val) {
document.frm2.fname.value = store[val]['name'];
document.frm2.fvalue.value = store[val]['value'];
document.frm2.submit(); // not working
setTimeout(function() { // not working
window.open("http://example.com/client, "_blank"), 3000);
});
});
});
</script>
表单没有值。输入具有值。你想在这里做什么? 'document.frm2.value.value = store [val] ['value'];' –
此外,为什么不使用'console.log()'来查看'$'的前2个赋值.each()'迭代?检查目标(以验证它们是您打算定位的目标)并分配新值。 –
您的表单一提交,您就会失去控制权。在提交表单之前打开弹出窗口。 – dave