我在一个页面上有多个表单都是这样的:ID值改变但选项可以类似。Jquery单选按钮提交表单
<form class="test"><td>4000</td>
<td align='center'><input type='radio' name='radio' value='car' checked></td>
<td align='center'><input type='radio' name='radio' value='boat' ></td>
<td align='center'><input type='radio' name='radio' value='Plane' ></td>
<input type='hidden' name='id' value='4000'/>
<input type='hidden' name='location' value='local'/>
<div class="form" style="display: none;">
</div></form>
使用JQuery我试图提交这个时,任何3个单选按钮被选中。
<script>
$("input[name='radio']").click(function() {
var CurrectForm=$(this).parents('.test:first');
$.post(
'do.php',
CurrectForm.serialize(),
function(response) {
CurrectForm.find('#form').html(response);
show(response);
}
);
});
</script>
我用类似上面复选框和下拉列表,已经工作得很好。但是这似乎并没有将这些值提交给do.php页面。提交的值以div格式显示。做一个var_dump($_POST);
会产生一个空的数组。
有人能指出我正确的方向吗? 谢谢
改变形式ti这似乎工作?
<td><form class="test">
<input type='radio' name='radio' value='car' checked>
<input type='radio' name='radio' value='boat' >
<input type='radio' name='radio' value='Plane' >
<input type='hidden' name='id' value='4000'/>
<input type='hidden' name='location' value='local'/>
<div class="form" style="display: none;">
</div></form></td>
为什么改变原因它工作?
Jfiddle与工作示例:) http://jsfiddle.net/QvpH5/
你有没有试过'console.dir(CurrectForm)'来看看你是正确的选择呢? – JoeCortopassi 2013-03-19 18:33:50