jQuery-读取表单值数组并显示它吗? [英] JQuery - Reading an array of form values and displaying it?
本文介绍了jQuery-读取表单值数组并显示它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单,在该表单中,我通过JQuery动态附加了隐藏值,这些隐藏值如下所示:
I have a form and in the form I'm appending hidden values dynamically via JQuery and these hidden values look like this:
<input type="hidden" name="times[]" value="{'time': '5:00pm','date': 'april 15th'}" />
<input type="hidden" name="times[]" value="{'time': '6:00pm','date': 'april 16th'}" />
<input type="hidden" name="times[]" value="{'time': '7:00pm','date': 'april 17th'}" />
使用JQuery如何遍历times []数组并输出每个值,以便该人在提交表单之前可以看到他们已经在表单中添加的所有值?
Using JQuery how can I iterate through the times[] array and output each value so the person can see all the values they have been adding in the form prior to submitting the form?
推荐答案
$('input[name="times[]"]').each(function(){
console.log($(this).val()); // Or anything you like.
});
或者您可以使用数组将所有获取的值压入其中.您将如何处理这些值完全取决于您.
Or you could use an array to push all fetched values in it. What are you going to do with the values is entirely up to you.
var values = [];
$('input[name="times[]"]').each(function(){
values.push($(this).val());
});
这篇关于jQuery-读取表单值数组并显示它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文