怎么获取这里的checkbox值?html代码如下,要获取选中的那项的值,里面的数字的地方都是在变的~
<form id="form1" name="form1" method="post" action="?action=count">
<label>
<input type="checkbox" name="group[12][24]" value="24" id="group_24" />
可以自己独立站着10秒以上</label>
<label>
<input type="checkbox" name="group[13][25]" value="25" id="group_25" />
能膝盖不着地爬行</label> <label>
<input type="checkbox" name="group[13][26]" value="26" id="group_26" />
能爬着上阶梯</label> <label>
<input type="checkbox" name="group[14][27]" value="27" id="group_27" />
能走2到3 步</label> <label>
<input type="checkbox" name="group[14][28]" value="28" id="group_28" />
能随着音乐在摇动身体</label> <label>
<input type="checkbox" name="group[15][29]" value="29" id="group_29" />
能独自走得很稳</label> <label>
<input type="checkbox" name="group[15][30]" value="30" id="group_30" />
能独力站起来</label>
<p align="center"><label> <input type="submit" name="button" id="button" class="pcbtn1" value="计算" /></label></p> </form>
<form id="form1" name="form1" method="post" action="?action=count">
<label>
<input type="checkbox" name="group[12][24]" value="24" id="group_24" />
可以自己独立站着10秒以上</label>
<label>
<input type="checkbox" name="group[13][25]" value="25" id="group_25" />
能膝盖不着地爬行</label> <label>
<input type="checkbox" name="group[13][26]" value="26" id="group_26" />
能爬着上阶梯</label> <label>
<input type="checkbox" name="group[14][27]" value="27" id="group_27" />
能走2到3 步</label> <label>
<input type="checkbox" name="group[14][28]" value="28" id="group_28" />
能随着音乐在摇动身体</label> <label>
<input type="checkbox" name="group[15][29]" value="29" id="group_29" />
能独自走得很稳</label> <label>
<input type="checkbox" name="group[15][30]" value="30" id="group_30" />
能独力站起来</label>
<p align="center"><label> <input type="submit" name="button" id="button" class="pcbtn1" value="计算" /></label></p> </form>
只设group[]
然后在接收页面用print_r($_POST["group"]);查看。
for(id = 24; id < 31; id++){
myValue[id] = document.getElementBuId('group' + id).value;
}
如果完全没办法确认id规律,并且数字也不连续,可以试试var input = document.getElementsByTagName('input');
for(var i=0;i<input.length;i++)
{
//对页面内的input进行遍历
}
<input type="checkbox" name="group[12][24]" value="24" id="group_24" checked/>
<input type="checkbox" name="group[13][25]" value="25" id="group_25" /><script>
var input = document.getElementsByTagName('input');
for(var i=0;i<input.length;i++)
{
if(input[i].checked)
{
alert(input[i].getAttribute('name') + '=' + input[i].getAttribute('value'));
}
}
</script>
$_POST['group']是一个3维数组。
key就是[]里对应的数字。
有值就表示选种了,没值就是没选。
$name .= ",".$value;
}
foreach($_POST['group'] AS $key => $val)
{
//$key 就是12, 13……
foreach($val AS $k => $v)
{
//$k 就是例子里的24, 25……
}
}