如何检查jQuery中是否已选中复选框?
问题: I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery. 我需要检查复选框的 checked 属性,并使用jQuery根据checked属性执行操作。 For example, if the age checkbox is checked, then I need to show a textbox to enter age, else hide the textbox. 例如,如果选中了年龄复选框,那么我需要显示一个文本框来输入年龄,否则隐藏该文本框。 But the following code returns false by default: 但是以下代码默认情况下返回 false : if ($('#isAgeSelected').attr('checked')) { $("#txtAge").show(); } else { $("#txtAge").hide(); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox"