我有一个表单,我正在尝试使用jquery从表单获取数据并对其进行验证。使用jquery将数据从表单带到变量的最佳方法是什么?
最佳答案
这是您可以使用的代码段-
$('#myForm').submit(function() {
// get all the inputs into an array.
var $inputs = $('#myForm :input');
// not sure if you wanted this, but I thought I'd add it.
// get an associative array of just the values.
var values = {};
$inputs.each(function() {
values[this.name] = $(this).val();
});
});
从stackoverflow-link得到了它
关于javascript - jQuery从表单获取数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11855781/