如何找到所有具有值的输入
How to find all inputs with values
目标是列出页面上所有输入的所有值,但不列出没有值的输入,两个问题:
$(":input").not("[id*=a_prefix_]").map(function()
{
var value = this.val();
if( value ) console.log(this.id + ":=" + value );
}
);
- this.val() 有问题,我得到一个错误 "Object doesn't support property or method 'val'",有什么解决方案?
- 如何移动检查以查看实际选择中是否有值,以便地图仅获取具有值的输入?
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();
目标是列出页面上所有输入的所有值,但不列出没有值的输入,两个问题:
$(":input").not("[id*=a_prefix_]").map(function()
{
var value = this.val();
if( value ) console.log(this.id + ":=" + value );
}
);
- this.val() 有问题,我得到一个错误 "Object doesn't support property or method 'val'",有什么解决方案?
- 如何移动检查以查看实际选择中是否有值,以便地图仅获取具有值的输入?
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();