目标是列出页面上所有输入的所有值,而不列出没有值的输入,两个问题:
$(":input").not("[id*=a_prefix_]").map(function()
{
var value = this.val();
if( value ) console.log(this.id + ":=" + value );
}
);
答案 0 :(得分:1)
var valueArray = $(":input")
// filter these things out, whatever they are
.not("[id*=a_prefix_]")
// filter only the elements that have a value
.filter(function(){ return this.value.trim(); })
// map the values
.map(function(){ return {[this.id]: this.value}; })
// turn the results into a real array, not a jQuery object of the values
.get();