我有以下HTML
<input type="hidden" name="conf1" value="7th IEEE/IFIP International Conference on Embedded and Ubiquitous Computing (EUC-09)">
<input type="hidden" name="conf2" value="IEEE International Symposium on Parallel and Distributed Processsing with Applications">
<input type="hidden" name="conf3" value="jkhga">
<input type="hidden" name="conf4" value="test">
<input type="hidden" name="conf5" value="The 3rd International Conference on Adaptive Business Information Systems (ABIS'09)">
<input type="text" name="published">我正在尝试使用jquery将隐藏字段的值放入数组中。以下是我尝试过的方法:
var conferences = new Array();
conferences[0] = $('#conf1').val();
conferences[1] =$("[name='conf2']").val();
conferences[2] =$("[name='conf3']").val();
conferences[3] = $("[name='conf4']").val();
conferences[4] =$("[name='conf5']").val(); 有人能指导我如何阅读它们吗?
提前感谢
院长
发布于 2010-07-07 05:35:17
如果你要使用jQuery,你可以这样做:
var array = $('input:hidden').map(function() {
return this.value;
}).get();.map()遍历集合,并将返回值放入jQuery对象中。
.get()从jQuery对象中检索数组。
发布于 2010-07-07 05:35:04
var conferences = [];
$('input:hidden[name^="conf"]').each(function() {
conferences.push($(this).val());
});发布于 2010-07-07 05:39:25
var array = $.map($('input:hidden'),function(i) {
return i.value;
});这会将值的数组分配给array,并且比使用$(selector).map()稍微少一些冗长,后者返回一个jQuery对象,然后需要调用get()来返回一个数组。
https://stackoverflow.com/questions/3190390
复制相似问题