如何根据每种具有值(value)的隐藏输入类型来计算li

HTML:

<ul id="room_1">
    <li>
        <div class="wrap participantlist wrap_body" style="color:#000000">
           <input type="hidden" name="hidden" value="1" id="channel">
        </div>
    </li>
    <li>
        <div class="wrap participantlist wrap_body" style="color:#000000">
            <input type="hidden" name="hidden" value="2" id="channel">
        </div>
     </li>
     <li>
        <div class="wrap participantlist wrap_body" style="color:#000000">
           <input type="hidden" name="hidden" value="" id="channel">
        </div>
     </li>
</ul>

Javascript:
 var participantLength = $("#room_1 li").length;
 console.log(participantLength);

具有值的隐藏输入的数量为2
 <input type="hidden" name="hidden" value="1" id="channel">


 <input type="hidden" name="hidden" value="2" id="channel">

所以输出应该是2

最佳答案

到那里,它应该告诉您有值(value)的输入数量

$("ul li input[value!='']").length

关于javascript - 根据隐藏的具有值的输入类型计算<li>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32515481/

10-11 15:21