JQuery 鼠标悬停时更改文本,return 鼠标移出时更改为原始文本

JQuery change text on mouse over and return to original on mouseout

我有这段代码,它适用于鼠标悬停,但是当 鼠标移开 离开 a 元素时,它不会显示原始文本p

$("a.brieflink").bind("mouseover", function() {
    $("div#brieftext").text($(this).data("text"));
});
$("a.brieflink").bind("mouseout", function() {
    $("brieftext").hide($(this).data("text"));
});

<a href="1.html" class="brieflink" data-src="article.jpg" data-text="text1">Brief 1</a>
<a href="2.html" class="brieflink" data-src="article.jpg" data-text="text2">Brief 2</a>
<a href="3.html" class="brieflink" data-src="article.jpg" data-text="text3">Brief 3</a>

<div id="brieftext"><p>Original text</p></div>

有人可以帮忙吗?

原因是当你使用$("div#brieftext").text($(this).data("text"))设置brieftext的文本时,你已经清除了它原来的内容,所以如果你想再次显示原来的内容,你需要调用html() 手动设置

$("a.brieflink").bind("mouseover", function() {
    $("#brieftext").text($(this).data("text"));
});
$("a.brieflink").bind("mouseout", function() {
    $("#brieftext").html("<p>Original text</p>");//set the content manaully
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<a href="1.html" class="brieflink" data-src="article.jpg" data-text="text1">Brief 1</a>
<a href="2.html" class="brieflink" data-src="article.jpg" data-text="text2">Brief 2</a>
<a href="3.html" class="brieflink" data-src="article.jpg" data-text="text3">Brief 3</a>

<div id="brieftext"><p>Original text</p></div>