min*_*004 -1 javascript jquery
如何在jquery中将所有输入字段值获取到数组?
请看下面的代码:
<input type="text" name="a" value="a" />
<input type="text" name="b" value="hello" />
<input type="text" name="c" value="world" />
<script type="text/javascript">
function get_fields_values(){
// too much code
var arr=[];
$.each($("input"),function(i,n){
arr.push(n.value)
});
return arr;
// is there any jquery method to get fields values to an array?
// $('input').xxx() ?
}
</script>
Run Code Online (Sandbox Code Playgroud)
var arr = $("input").map(function(){ return this.value; }).get();
Run Code Online (Sandbox Code Playgroud)
完整的代码是,
function get_fields_values(){
return $("input").map(function(){ return this.value; }).get();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |