我有两个单选按钮
Popular
Others
两个按钮
Edit
Cancel
最初,当我点击编辑按钮时,单选按钮将被禁用,单选按钮应该被启用,而当我再次点击取消按钮时,它应该被禁用。
目前我只能在单击编辑按钮时启用它,但是当我单击取消按钮时无法禁用它有人可以帮助我实现它谢谢!
http://jsfiddle.net/UhEut/452/
HTML
<div>
<label>
<input id='r_popular' class='pop_others' type='radio' name='section_pop_others' disabled checked />Popular
</label>
<label>
<input id='r_others' class='pop_others' type='radio' name='section_pop_others' disabled />Others
</label>
<button class="edit">Edit</button>
<button class="cancel">cancel</button>
</div>
JQuery
<script>
$(document).click('.edit',function()
{
$('input[name=section_pop_others]').attr("disabled",true);
});
$(document).click('.cancel',function()
{
$('input[name=section_pop_others]').attr("disabled",false);
});
</script>
最佳答案
为什么您的代码不起作用?
$(document).click('whatever here',function(){
// This block is run for every click event occuring anywhere on the document
}
什么是正确的方法:
$('Your selector').click(function(){
// This block will run when click event occurs on Your selector
})
更改代码:
$(document).click('.cancel',function()
$(document).click('.edit',function()
为此:
$('.cancel').click(function(){
$('.edit').click(function()
关于javascript - 单击按钮启用和禁用单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33436223/