admin管理员组文章数量:1420166
I was trying to solve this problem, but my reset button just can't uncheck the radio button..... :( Hope experts here can help me to solve my problem. Thx!!!!
just created the fiddle /
<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;
})
});
I was trying to solve this problem, but my reset button just can't uncheck the radio button..... :( Hope experts here can help me to solve my problem. Thx!!!!
just created the fiddle http://jsfiddle/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;
})
});
Share
Improve this question
edited Jul 9, 2014 at 7:51
Michael Ngooi
asked Jul 9, 2014 at 7:37
Michael NgooiMichael Ngooi
1315 silver badges11 bronze badges
2
- it would be better if you create a Fiddle – Amit Soni Commented Jul 9, 2014 at 7:47
- That fiddle does not have jQuery and jQuery UI enable (options on the left). Have added working answer below with JSFiddle. – iCollect.it Ltd Commented Jul 9, 2014 at 7:52
2 Answers
Reset to default 6You need to refresh the jQuery button
state after changing the underlying radio buttons.
JSFiddle: http://jsfiddle/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 create separate elements, so changing the radio button state has no immediate effect on them.
Reference: http://api.jqueryui./button/#method-refresh
If you view the DOM, in say Chrome's F12 DOM inspector, you will see button()
creates a LABEL and SPAN preceding each radio button. The actual radio button is styled out with the class ui-helper-hidden-accessible
Try this:
<script src="http://ajax.googleapis./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>
Basiclly, it unchecks all checkboxes with the class .myCheck
本文标签: javascriptjquery how to uncheck radio buttonStack Overflow
版权声明:本文标题:javascript - jquery how to uncheck radio button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745310273a2652897.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论