[英]Get checked values from checkboxes
I have this check boxes that I need to get its checked values: 我有此复选框需要获取其检查值:
In this example, I would expect to get Ubuntu , because it is checked. 在此示例中,我希望得到Ubuntu ,因为它已选中。
<div class="checkbox">
<label for="my_label_3-4">
<input id="my_label_3-4" type="checkbox" value="5" name="my_label_3[]" aria-invalid="false"></input>
Windows 7, 8
</label>
</div>
<div class="checkbox">
<label for="my_label_3-5">
<input id="my_label_3-5" type="checkbox" value="6" name="my_label_3[]" aria-invalid="false"></input>
Mac OS
</label>
</div>
<div class="checkbox">
<label for="my_label_3-6">
<input id="my_label_3-6" type="checkbox" checked="" value="7" name="my_label_3[]" aria-invalid="false"></input>
Ubuntu
</label>
</div>
<div class="checkbox">
<label for="my_label_3-7">
<input id="my_label_3-7" type="checkbox" value="8" name="my_label_3[]" aria-invalid="false"></input>
FreeBSD
</label>
</div>
How do I do so? 我该怎么做?
This is what I did so far, but hasn't return any result: 这是我到目前为止所做的,但是没有返回任何结果:
echo 'checkbox';
foreach ($html->find('my_label_3') as $id) {
echo $id; // returns 'checkbox'
}
Using Simple HTML Dom for parsing process 使用简单HTML Dom进行解析
try using the label
to identify the nodes, as Ubuntu is not the value of the input
. 尝试使用
label
来标识节点,因为Ubuntu不是input
的值。 It is the text of the label
, the value of that input
is 7. 它是
label
的文本,该input
值为7。
foreach ($html->find('label[for^="my_label_3-"') as $label) {
if (!empty($label.find('input[checked]'))){
echo $label->innertext;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.