这里是 jquery 的新手,现在我可以在选择一个单选按钮时使用隐藏/显示功能。但是,在我选择一个单选按钮后,无法取消选择所有选项并隐藏 div。理想情况下,我喜欢添加一个小的“X”,用户可以单击它来重置我的单选按钮和汽车数量,我想你们可能明白我的意思。非常感谢您的帮助!
html
<div id="myRadioGroup">
2 Cars<input type="radio" name="cars" value="2" />
3 Cars<input type="radio" name="cars" value="3" />
<div id="Cars2" class="desc">
2 Cars Selected
</div>
<div id="Cars3" class="desc">
3 Cars
</div>
</div>
j查询
$(document).ready(function() {
$("div.desc").hide();
$("input[name$='cars']").click(function() {
var test = $(this).val();
$("div.desc").hide();
$("#Cars" + test).show();
});
});
最佳答案
这是否满足您的需求?
<a href="" onclick="$('input:checked').removeAttr('checked');
$('.desc').hide();return false;">Reset</a>
关于jquery html/css : adding a 'close' button to my div that was added on . 点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7867801/