从复选框获取检查值 [英] Get checked values from checkboxes
本文介绍了从复选框获取检查值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个复选框,我需要得到它的检查值:
在这个例子中,我希望得到 Ubuntu ,因为它被检查。
< div class =checkbox>
< label for =my_label_3-4>
< input id =my_label_3-4type =checkboxvalue =5name =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-5type =checkboxvalue =6name =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-6type =checkboxchecked =value =7name =my_label_3 []aria-invalid =false>< / input>
Ubuntu
< / label>
< / div>
< div class =checkbox>
< label for =my_label_3-7>
< input id =my_label_3-7type =checkboxvalue =8name =my_label_3 []aria-invalid =false>< / input>
FreeBSD
< / label>
< / div>
我该怎么做?
这是我到目前为止所做的,但没有返回任何结果:
echo'checkbox';
foreach($ html-> find('my_label_3')as $ id){
echo $ id; //返回'checkbox'
}
使用简单的HTML Dom解析过程
解决方案
尝试使用标签
标识节点,如 Ubuntu 不是输入
的值。它是标签
的文本, input
的值是7。
foreach($ html-> find('label [for ^ =my_label_3-')as $ label){
if(!empty ($ label.find('input [checked]'))){
echo $ label-> innertext;
}
}
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.
<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
解决方案
try using the label
to identify the nodes, as Ubuntu is not the value of the input
. It is the text of the label
, the value of that input
is 7.
foreach ($html->find('label[for^="my_label_3-"') as $label) {
if (!empty($label.find('input[checked]'))){
echo $label->innertext;
}
}
这篇关于从复选框获取检查值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文