问题是,当我在单选按钮上按下键时,元素MyFunc
会触发两次——一次为onkeypress
事件,另一次为“click”事件。
问题是“为什么?”我需要以两种不同的方式处理此问题,但现在我无法识别最初的事件是什么。当我点击鼠标时,它只会触发“click”事件。
<ul>
<li>
<input type="radio" onkeypress="MyFunc(event, this)" onclick="MyFunc(event, this)" name="myList" id="MyId_1" />Topic 1
<input type="radio" onkeypress="MyFunc(event, this)" onclick="MyFunc(event, this)" name="myList" id="MyId_2" />Topic 2
</li>
</ul>
function MyFunc(e, obj) {
alert(e.type); // alerts "keypress" and then "click"
// Do my stuff
}