繁体   English   中英

jQuery如何取消选中单选按钮

[英]jquery how to uncheck radio button

我正在尝试解决此问题,但是我的重置按钮无法取消选中单选按钮..... :(希望这里的专家可以帮助我解决我的问题。谢谢!!!

刚刚创建了小提琴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 Buttons创建单独的元素,因此更改单选按钮状态不会立即对其产生影响。

参考: http : //api.jqueryui.com/button/#method-refresh

如果您查看DOM,例如在Chrome的F12 DOM检查器中,您将看到button()在每个单选按钮之前创建一个LABEL和SPAN。 实际的单选按钮使用ui-helper-hidden-accessible类进行样式设置

尝试这个:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body>

<h3>A demonstration of how to uncheck a Checkbox</h3>

Checkbox: <input type="checkbox" class="myCheck" checked>
Checkbox2: <input type="checkbox" class="myCheck" >
Checkbox3: <input type="checkbox" class="myCheck" >
<p>Click the "Try it" button to check the checkbox.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
$(".myCheck").prop('checked' , false);
}
</script>

</body>

基本上,它会取消选中类.myCheck的所有复选框

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM