Javascript 无线信箱不是';在使用JQuery更改其“已检查”状态后,未提交
我有一个带有多个RadioBox的表单,我可以根据用户交互更改其选中状态 当我加载页面并在不更改任何内容的情况下提交它时,POST请求携带选中的radiobox的值,但是当我在某个用户行为之后使用JQuery更改状态时,更改的radiobox的值不会被提交Javascript 无线信箱不是';在使用JQuery更改其“已检查”状态后,未提交,javascript,jquery,html,Javascript,Jquery,Html,我有一个带有多个RadioBox的表单,我可以根据用户交互更改其选中状态 当我加载页面并在不更改任何内容的情况下提交它时,POST请求携带选中的radiobox的值,但是当我在某个用户行为之后使用JQuery更改状态时,更改的radiobox的值不会被提交 <input checked="checked" name="resident" type="radio" value="no"> <input name="resident" type="radio" value="yes
<input checked="checked" name="resident" type="radio" value="no">
<input name="resident" type="radio" value="yes">
完成此操作后,RadioBox的变化如下:
<input name="resident" type="radio" value="no">
<input name="resident" type="radio" value="yes" checked="checked">
您应该使用prop而不是attr。Attr指的是默认值,而prop指的是当前值 见: 此外,如果希望取消检查,只需将其设置为false 因此,您的代码如下所示:
$('[data-toggle="section-radio"]').click(function(){
section = $(this).closest('.tab-pane');
section.find('[data-toggle="section-radio"]').removeClass('active');
$(this).addClass('active');
$(section).find('[type="radio"]').prop('checked', false);
$(this).find('[type="radio"]').prop('checked', true);
});
你是如何提交表格的?你能发布元素的其余部分吗?我只是使用一个普通的提交按钮,我编辑了这个问题。add
。attr('checked',true)
是一个布尔值,不是字符串。
<input type='submit' class='btn btn-finish btn-fill btn-warning btn-wd btn-sm' name='finish' value='save' />
$('[data-toggle="section-radio"]').click(function(){
section = $(this).closest('.tab-pane');
section.find('[data-toggle="section-radio"]').removeClass('active');
$(this).addClass('active');
$(section).find('[type="radio"]').prop('checked', false);
$(this).find('[type="radio"]').prop('checked', true);
});