我不确定我是否正确编写了HTML。我的脚本可能因此没有运行。我使用段落在箭头和上面的文本之间创建空格(未显示)。
<div class="littlebg">
<div class="text">
<hr>
Renowned Japanese author Haruki Murakami said he owns over <a href="http://www.nytimes.com/2011/10/23/magazine/the-fierce-imagination-of-haruki-murakami.html?pagewanted=5&ref=baseball&_r=0">10,000 records</a>. He often references music in his stories, particularly the genres classical, jazz and American pop. His first job was at a record store, and he once ran a jazz bar, called the Peter Cat, in Tokyo with his wife.
<a href="#begin2">
<p><div class="arrow"></div></p>
<a href="#begin2">
<p>
<div class="arrow"></div>
</p>
</a>
<script>
$("div.arrow").hover(function() {
$('this').css("border", '#4da6ff');
});
</script>
</div>
答案 0 :(得分:2)
引用为$(this)
或this
,而非$('this')
。
此外,您只考虑 mouseenter ,当鼠标离开元素并恢复之前的值时,您应该编写第二个回调。
答案 1 :(得分:1)
你的jQuery有点偏,它应该是:
$(".arrow").hover(function() {
$(this).css("border", "1px solid #4da6ff");
});
但你可以简单地用CSS做这个,没有像这样的jQuery:
.arrow:hover {
border: 1px solid #4da6ff;
}