<?php
if($_POST) {
print_r($_POST);
exit;
}
?>
<script src="bootstrap/js/jquery.js"></script>
<script>
$(function() {
//在 form 标记中就这样
$.post(location, $('form').serialize(), function(d) {alert(d)});
// 不在 form 标记中就这样
d = {};
$("input[name^='sort']").each(function(i, el) {
d[el.name] =$(this).val();
});
$.post(location, d, function(d) {alert(d)});
});
</script>
<form>
<input type="text" name="sort[1]" value="1" />
<input type="text" name="sort[2]" value="2" />
<input type="text" name="sort[3]" value="3" />
</form>
jquery 获取 input 名为数组
最新推荐文章于 2024-08-18 02:07:00 发布
本文介绍了一种使用jQuery简化表单POST提交的方法。通过示例代码展示了如何收集表单元素的值并使用$.post函数发送到服务器,同时提供了不在<form>标记中的元素提交方案。

4770

被折叠的 条评论
为什么被折叠?



