我尝试了以下操作,在鼠标悬停时将跨度更改为红色,在mouseout上将其更改为黑色:
<span onmouseover="this.style.color='red' onmouseout=this.style.color='black'">Mouse over me!</span>
但它不起作用!
如何使用javascript将多个事件绑定到单个元素?
答案 0 :(得分:2)
你忘记了引言。
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
^ ^
答案 1 :(得分:2)
忘了引用..
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
答案 2 :(得分:1)
您将onmouseout
置于onmouseover
事件中,这是不正确的。
试试这个:
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>