【发布时间】:2010-07-26 12:55:08
【问题描述】:
我想在单击按钮时选择一个复选框。
<form action="" method="post" id="form2">
<input type="checkbox" id="checkone" value="one" name="one" />
<input type="button" value="Click me" id="buttonone"/>
</form>
当我尝试以下操作时,复选框没有被选中
$('#buttonone').click(function() {
$('#checkone').checked=true;
});
然后我尝试了:
$('#buttonone').click(function() {
document.getElementById('checkone').checked=true;
});
这次复选框被选中。为什么不使用 jquery $ 函数选择它?
【问题讨论】:
-
@illarra - 这不是最好的方法,这是 jQuery 新手快速但不能有效解决问题的最佳方法问题...而且该链接根本没有回答问题。他问为什么
.checked = true不在这里工作?...我完全没有看到这一点,我怀疑你会在 10 秒内在 google 上找到答案。跨度> -
你是对的@Nick Craver,我在这里误解了问题的第二部分。我试图撤消我的 -1 但现在不能。 @Anurag 的回答很清楚。
-
@illarra - 已编辑,现在发布您的投票 :)
标签: javascript jquery html forms properties