gpt4 book ai didi

php - Jquery 单选按钮提交表单

转载 作者:行者123 更新时间:2023-12-01 05:56:06 25 4
gpt4 key购买 nike

我在一页上有多个表单,都是这样的:ID 值发生变化,但选项可以相似。

<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); 会产生一个空数组。

有人能指出我正确的方向吗?谢谢

更改表单这似乎有效?

<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/

最佳答案

我的猜测是,您的页面上有多个带有 test 类的表单。发生的情况是,当您使用 parents() 时,您没有意识到它首先找到所有祖先,然后然后搜索 .test:first。无论单击哪个表单,这都将返回第一个表单的值。

查看此 jsFiddle 以查看修复(将 .parents 更改为 .parent):http://jsfiddle.net/SDzzr/

关于php - Jquery 单选按钮提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15507540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com