我有一个表单,我正在尝试使用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();
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17170 次 |
| 最近记录: |