【发布时间】:2013-09-22 11:47:13
【问题描述】:
我有一个可以使用 jQuery 打开和关闭的 div。悬停时链接文本需要更改,因此如果 div 打开,文本将显示“关闭”,反之亦然。但是,我不知道如何在鼠标移出时将链接文本返回到其原始值(例如,在 example jsFiddle 中,文本在未悬停时应更改回 Hello)。
有什么想法吗?
HTML:
<div>
<h4>HELLO</h4>
<p>Loads of interesting content etc</p>
<p>Loads of interesting content etc</p>
<p>Loads of interesting content etc</p>
<p>Loads of interesting content etc</p>
</div>
JS:
$("h4").click(function () {
var par = $(this).parent();
par.children("p").slideToggle(500);
if (par.hasClass("closed")) {
par.animate({
height: 180
}, 500);
};
if (!par.hasClass("closed")) {
par.animate({
height: 30
}, 500);
};
par.toggleClass("closed");
});
$("h4").hover(
function () {
if ($(this).parent().hasClass("closed")) {
$(this).html("OPEN");
} else {
$(this).html("CLOSE");
}
},
function () {
//how do I get back the original value on mouseout?
});
编辑:我得到的解决方案是here。
【问题讨论】:
标签: jquery hover jquery-hover