javascript获取指定div内的所有input框的数量
html页面代码
<ul class="jxs_list jxs_list_sec shop_checked" id="after_shop_id_1"><div data-shop_id="10742" id="after_vip-shop_id_10742_1">国贸<input type="hidden" name="after_shop_id_1[]" value="10742"><span class="delete_shop_id" title="点我删除" data-shop_id="10742" onclick="after_delete_shop_div(1,10742)">X</span></div><div data-shop_id="87299" id="after_vip-shop_id_87299_1">1111<input type="hidden" name="after_shop_id_1[]" value="87299"><span class="delete_shop_id" title="点我删除" data-shop_id="87299" onclick="after_delete_shop_div(1,87299)">X</span></div><div data-shop_id="10764" id="after_vip-shop_id_10764_1">桃子<input type="hidden" name="after_shop_id_1[]" value="10764"><span class="delete_shop_id" title="点我删除" data-shop_id="10764" onclick="after_delete_shop_div(1,10764)">X</span></div></ul>
js使用方法
function after_xzshop_number() {
var shop_length = document.getElementById('after_shop_id_1' ).getElementsByTagName('input').length;
$('#after_selected_shop_1').html('已选中<b style="color:#FF0000">' + shop_length + '</b>家门店');
}
jquery使用方法
var shop_length = $('#after_shop_id_' + num).find("input[name='after_shop_id_"+num+"[]']").length;
var shop_length = $('#after_shop_id_' + num).find(":input").length;