//save tablet jQuery("#savetablet"+jTablets[i].idtablets).on('click',function() { alert("alertsepy2..."); console.log(jTablets[i].idtablets); jQuery("#tablet"+jTablets[i].idtablets+" .detailsrow").each(function( index ) { $(this).each(function( index2 ) { console.log($(this).html()); }); }); }); <div class="column0"><input type="text" value="-D"></div> <div class="column1"><input type="text" value="D"></div> <div class="column2"><input type="text" value="D"></div> <div class="column3"><input type="number" value="0"></div> <div class="column4"> <input type="number" value="0"></div> <div class="column5"> <input type="number" value="0"></div> <div class="column6"><input type="number" value="0"></div> <div class="column7"><input type="number" value="0"></div> <div class="column8"><input type="number" value="0"></div> <div class="column9"> <input type="number" value="0"></div> <div class="column10"> <input type="number" value=""></div> <div id="tablet17row0" class="column11">11</div> <div class="column0"><input type="text" value="-D"></div> <div class="column1"><input type="text" value="D"></div> <div class="column2"><input type="text" value="D"></div> <div class="column3"><input type="number" value="0"></div> <div class="column4"> <input type="number" value="0"></div> <div class="column5"> <input type="number" value="0"></div> <div class="column6"><input type="number" value="0"></div> <div class="column7"><input type="number" value="0"></div> <div class="column8"><input type="number" value="0"></div> <div class="column9"> <input type="number" value="0"></div> <div class="column10"> <input type="number" value=""></div> <div id="tablet17row1" class="column11">21</div>
我有上述jQuery .each()将附加的HTML输出到控制台.在这种情况下,我想仅提取类型为text或type number的输入元素的val().有没有办法隔离输入元素,所以我可以把它们的值输出到数组中?
提前致谢…
解决方法
提取号码:
var arrNumber = new Array(); $('input[type=number]').each(function(){ arrNumber.push($(this).val()); })
var arrText= new Array(); $('input[type=text]').each(function(){ arrText.push($(this).val()); })
编辑:.map实现
var arrText= $('input[type=text]').map(function(){ return this.value; }).get();