是否可以在链接中执行 jQuery 的代码?例如,我可以这样做吗?
<a href="index.php" onmouseover="$(this).css("background-color","#111111");">Home</a>
我想在某些链接中使用它来创建一些效果,而不需要触及更多 CSS。
最佳答案
您将使用 JavaScript 中的引号将属性引号括起来。
要么逃离他们,
onmouseover="$(this).css(\"background-color\",\"#111111\");"
或者对内部或外部使用单引号。
onmouseover='$(this).css("background-color","#111111");'
关于javascript - 我应该如何使用 JQuery 更改鼠标悬停时 DOM 元素的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16698009/