我在检查复选框中的值时遇到问题。我试图清理代码。
我已经能够选中所有选中的复选框(不是每行),或者我可以获得每行的复选框ID但不是所选的值。我很确定我可以将值传输到另一个页面,但不知道如何获取它们。
在此非常感谢!
//php variables used
$pages = 2
$size = 4
<form id="form" name="cb">
<div style=" width:800px; height:500px; overflow:auto">
<h2>Select Editions</h2>
<table id='table' name='table' border=1 cellpadding=7 width=50% height=50% align='center'>\n
for($x = 1; $x <= $pages; $x++) :
print "<td id='page_$x' class='page_button' align='center' custom='0' >Page $x - ";
for($i = 1; $i <= $size; $i++) :
print "<input type='checkbox' class='ebutton' id='etype_$x' name='checks[]' value='$i' /> $i";
endfor;
</td>
</tr>
//php end for loop
endfor;
</div>
</form>
以下是基于复选框类的类更新的Javascript
$(document).ready(function() {
$(".ebutton").change(function() {
var idp = $(this).attr("id").split("_");
var page_num = idp[1];
// I need to find out how to get the checkboxes that are checked per row. Ex: 01,02
//var editions = ?;
//alert(editions);
var hidden_id = "#etype_page_" + page_num;
if($(hidden_id).length < 1) {
$("#base").append('<input type="hidden" id="etype_page_'+ page_num +'" name="'+ page_num +'" value="'+ editions +'" class="hidden_edtype" custom="' + editions +'">');
} else {
$(hidden_id).val($(this).val());
}
update_eShow();
});
});
function update_eShow() {
$("#eShow").html('');
$(".hidden_edtype").each(function() {
var page = $(this).attr("name");
var value = $(this).attr("custom");
$("#eShow").append('page:' + page + ' values:' + value +'<br>');
});
}
页面如下所示:
答案 0 :(得分:0)
该名称应具有不同的编号,名称应以与您的ID一样唯一的形式发送。
尝试将名称设置为id:name='etype_$x'
然后使用调试控制台(如果使用chrome hit f12),然后转到网络并可视化表单中发送的变量和值。
答案 1 :(得分:0)
var $editions = $("#page_"+page_num+" input[checked=checked]");
var editions = [];
$editions.each(function(input) {
editions.push($(input).val());
});
答案 2 :(得分:0)
您不需要javascript将复选框发送到php
您可以将检查命名为checks[$page][]
:
print "<input type='checkbox' class='ebutton' id='etype_$x' name='checks[$x][]' value='$i' /> $i";
在您的操作页面中,您将在$ _POST(pr $ _GET)[“检查”] [1]中为一个数组检查第1页的值(如果有的话)
答案 3 :(得分:0)
现在,知道它是一个弹出窗口,向父母发送支票......
进行如下检查:
print "<input type='checkbox' class='ebutton checks$x' id='etype_$x' name='checks".$x."[]' value='$i' /> $i";
将页面1的检查类别作为“checks1”,第2页的类检查如“checks2”,...
并获得检查的那些:
var page_num = idp[1];
var checks=$('checks'+page_num).attr('checked',true); //to get all checked checkboxes of the class checks+page_num
var editions="";
checks.each(function(ch) {
editions+=$(ch).val()+',';
}
和版本将该页面的所有选中值用','
分隔