jquery输入数组表单ajax [英] Jquery input array form ajax
本文介绍了jquery输入数组表单ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 jQuery 变量 users
中获取输入数组 username
值?
How do i get the input array username
values in the jQuery variable users
?
<input type='text' name='username[]' class='users' value='test1' />
<input type='text' name='username[]' class='users' value='test2' />
<input type='text' name='username[]' class='users' value='test3' />
<div class='submit'>Submit</div>
<script type="text/javascript">
$(function() {
$('.submit').click(function() {
var users =
var dataString = 'users=' + users;
$.ajax({
type:'POST',
url:'users.php',
data: dataString,
success: function() {
}
});
});
});
</script>
推荐答案
查看 jQuery.serialize()
.它应该为您提供一组用户名.
Check out jQuery.serialize()
. It should give you an array of the usernames.
var users = $('input:text.users').serialize();
您可以使用选择器,无论是懒惰还是特定:.users
,input.users
,form .users
都可以,加上还有一些.
You can be however lazy or specific with the selector: .users
,input.users
,form .users
would all work, plus a few more.
对于这个例子:
// users =
username[]=test1&username[]=test2&username[]=test3
这取决于您的服务器端技术,它将作为键用户名"(例如 PHP)的字符串数组出现在请求中.
Which, depending on your server-side technology, will come through in the request as an array of strings for the key "username" (PHP, for example).
这篇关于jquery输入数组表单ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文