Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经开始使用 qUnit 测试我的 UI,所以我需要模拟一些用户交互。是否可以“模拟”用户使用 javascript 单击复选框?
谢谢各位。在我发布问题后大约两秒钟,我想通了。正如你所说,比我想象的要简单
document.getElementById('cb1').click();
成功了
编辑:似乎在 IE7(可能还有其他浏览器)中,单击方法实际上不会选中复选框。因此,要完全模拟,您需要在单击之前“选中”复选框
document.getElementById('cb1').checked=true document.getElementById('cb1').click();
你可以看看这个:
通过javascript模拟buttonclick
这是另一种方式,所以我不确定它是否也适用于复选框。