jQuery获取输入数组字段 [英] Jquery get input array field
本文介绍了jQuery获取输入数组字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里找到了类似的问题,但对我没有任何帮助.
I've found similar questions here but nothing works for me.
具有类似以下内容的输入:
have inputs like:
<input type="text" value="2" name="pages_title[1]">
<input type="text" value="1" name="pages_title[2]">
尝试获取以下字段:
$('input[name="pages_title[]"]')
但结果为空:(
如何获取所有字段?
我只能像$('input[name="pages_title[1]"]')
how to get all fields?
I can only get it like $('input[name="pages_title[1]"]')
推荐答案
使用开始与选择器
$('input[name^="pages_title"]').each(function() {
alert($(this).val());
});
注意:与@epascarello一致,更好的解决方案是将一个类添加到元素中并引用该类.
Note: In agreement with @epascarello that the better solution is to add a class to the elements and reference that class.
这篇关于jQuery获取输入数组字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文