重置下拉列表中的复选框值

时间:2014-09-17 17:01:09

标签: javascript jquery checkbox drop-down-menu

我正在尝试为复选框实现重置功能。这是我的测试代码,但它没有给出输出。

      <html>
 <head>
 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
 </head>

<body>
<div class="dropdown" id="drop">
<form name="frmChkForm" id="frmChkForm">Checkme
<input type="checkbox" name="chk1" class="group1">
<input type="checkbox" name="chk2" class="group1">
</form>
</div>
<a href="javascript:void(0)" onclick="reset()"> Reset All </a>

<script>
 function reset() {
    $('dropdown input[type="checkbox"]').prop('checked', false); 
    console.log(1);
}
</script>
</body>
</html>

请指导我在这里做错了什么?

2 个答案:

答案 0 :(得分:0)

首先:修复你的HTML。您在下拉列表中错过了结束>

然后你只需要修改你的jquery选择器:

$('.dropdown input[type="checkbox"]') // the . is for class, # is for id. 

答案 1 :(得分:0)

这样的事情可能会起到作用:

$('#frmChkForm').find(':checked').each(function() {
   $(this).removeAttr('checked');
});
相关问题