gpt4 book ai didi

javascript - jquery如何取消选中单选按钮

转载 作者:行者123 更新时间:2023-11-30 10:14:28 24 4
gpt4 key购买 nike

我试图解决这个问题,但我的重置按钮无法取消选中单选按钮.....:(希望这里的专家能帮我解决我的问题。谢谢!!!!

刚刚创建了 fiddle http://jsfiddle.net/8GLPC/

<input type="radio" class="radio" name="r[][9]" id="id_19" value="1|9">
<label for="id_19">Choice 1</label>
<input type="radio" class="radio" name="r[][9]" id="id_29" value="2|9">
<label for="id_29">Choice 1</label>
<button class="reset1" value="9">Reset</button>


$(document).ready(function(){
$(".radio")
.button();

$(".reset1")
.button()
.click(function(){
var radio = $('[name="r[][9]"]');
radio.prop('checked',false);
return false;
})
});

最佳答案

更改底层单选按钮后,您需要刷新 jQuery button 状态。

JSFiddle:http://jsfiddle.net/TrueBlueAussie/BPv7F/1/

$(document).ready(function(){
$(".radio")
.button();

$(".reset1")
.button()
.click(function(){
var radio = $('[name="r[][9]"]');
radio.prop('checked', false).button("refresh");
return false;
})
});

jQuery UI 按钮创建单独的元素,因此更改单选按钮状态不会立即影响它们。

引用:http://api.jqueryui.com/button/#method-refresh

如果您查看 DOM,例如 Chrome 的 F12 DOM 检查器,您将看到 button() 在每个单选按钮之前创建了一个 LABEL 和 SPAN。实际的单选按钮是用 ui-helper-hidden-accessible

类设计的

关于javascript - jquery如何取消选中单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24647879/

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