我不确定如何做到这一点,并尝试以下无济于事:
someElement.onmouseover=function(event) {
if(!event) { e = window.event; }
if(event.typeof=="mouseup") {
//change what [i]this[/i] returns (this = null doesn't work either)
//and how could I find a way to allow this event handler to alter itself under the
}
}
非常感谢任何帮助!
答案 0 :(得分:0)
> someElement.onmouseover=function(event)
> { if(!event) { e = window.event; }
我认为你的意思是:
event = window.event
> if(event.typeof=="mouseup") {
我认为你的意思是:
if (event.type == 'mouseup') {
> //change what [i]this[/i] returns
> (this = null doesn't work either)
函数的 this 关键字的值在实例化期间设置,您无法更改它。
> //and how could I find a way to allow
> this event handler to alter itself
> under the } }
改变自己?它可以设置一个不同的监听器,如果这是你的意思:
this.onmouseover = someOtherFunction;
玩这个:
<script>
function showType(e) {
console.log(e.type);
}
</script>
<input
onclick="showType(event);"
onmouseover="showType(event);"
onmouseout="showType(event);"
onmousedown="showType(event);"
onmouseup="showType(event);"
onkeydown="showType(event);"
onkeyup="showType(event);"
onkeypress="showType(event);"
value="Do stuff in here"
>