怎么实现使用js实现动态添加标签添加hover事件

怎么实现使用js实现动态添加标签添加hover事件,第1张

一般都用jQuery写:简单方便。

$(selector).hover(handlerInOut) 。

等同于:$( selector ).on( "mouseover mouseout", handlerInOut )

就可以触发鼠标放上去的事件

hover就是鼠标放上去后,标签样式,可以给a标签注册一个onmouseover和onmouseout事件,在事件处理函数中改变标签的样式。

<a href="" id="aa">dsdfdsfdfsdfds</a>

<script>

document.getElementById("aa").onmouseover=function(){

document.getElementById("aa").style="color:red"

}

document.getElementById("aa").onmouseout=function(){

document.getElementById("aa").style="color:blue"

}

</script>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11820713.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存