可以使用.data()
方法存储原始html http://jsfiddle.net/94nPv/3/
jQuery(document).ready(function($) {
$('h5').toggle(function() {
var $this = $(this);
$this.data('originalText',$this.html());
$this.parent('div.softwarebox').animate({ height: "700px" });
$this.html("Close");
}, function() {
var $this = $(this);
$this.parent('div.softwarebox').animate({ height: "19px" });
$this.html($this.data('originalText'));
});
});
略微优化(无需额外调用 .html 或 .data):http: //jsfiddle.net/94nPv/7/
jQuery(document).ready(function($) {
$('h5').each(function(){
var $this = $(this);
$this.data('originalText',$this.html());
});
$('h5').click(function() {
var $this = $(this);
if ($this.text() === "Close") {
$this.html($this.data('originalText'));
$this.parent('div.softwarebox').animate({
height: "19px"
});
}
else {
$this.text("Close");
$this.parent('div.softwarebox').animate({
height: "700px"
});
}
});
});