0
我想获取多个复选框值,我尝试了一下,我无法得到为什么这里意味着选择和选项不存在,我试图这样做,但我无法获得值如何在没有选择标签的情况下获得多个值
<div class="dropdown-menu dropdown-menu" id="property_type2" name="property_type2" role="menu" style="color:#333;width:315px;height: 102px;border-radius:0px;" >
\t <div class="chkbox" style="padding-left:5px;">
\t \t <label class="checkbox-inline checkbox-success">
\t \t <input type="checkbox" id="Check1" value="flat"> Flat
\t \t </label>
\t \t
\t \t <label class="checkbox-inline">
\t \t <input type="checkbox" id="Check2" value="villa"> House/Villa
\t \t </label>
\t \t
\t \t <label class="checkbox-inline">
\t \t <input type="checkbox" id="Check3" value="plot"> Plot
\t \t </label>
\t \t
\t </div>
</div>
var foo = [];
\t \t $('.chkbox :selected').each(function(i, selected){
\t \t foo[i] = $(selected).text();
\t \t });
console.log(foo);
可能还有其他的问题,但可以肯定你的选择.chkbox不匹配的任何元素。将class ='chkbox'添加到复选框元素的html,然后重试。 –