在 javascript 中绑定多个事件
Bind multiple events in javascript
我尝试了以下方法将跨度在鼠标悬停时更改为红色,在鼠标移开时更改为黑色:
<span onmouseover="this.style.color='red' onmouseout=this.style.color='black'">Mouse over me!</span>
但是没用!
如何使用 javascript 将多个事件绑定到单个元素?
您将 onmouseout
放入 onmouseover
事件中,这是不正确的。
试试这个:
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
你忘了引号。
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
^ ^
忘记引用..
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
我尝试了以下方法将跨度在鼠标悬停时更改为红色,在鼠标移开时更改为黑色:
<span onmouseover="this.style.color='red' onmouseout=this.style.color='black'">Mouse over me!</span>
但是没用!
如何使用 javascript 将多个事件绑定到单个元素?
您将 onmouseout
放入 onmouseover
事件中,这是不正确的。
试试这个:
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
你忘了引号。
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
^ ^
忘记引用..
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>