工作演示小提琴链接在这里
可见文本需要隐藏,隐藏应使用当前可见文本更新,
在单击的绑定事件中移动这 3 行将为您解决问题:
var visibleText = $("#hidewrap a span").text();
var dynText = textChange.text() == visibleText ? hiddenText : visibleText;
hiddenText = textChange.text();
jQuery代码
$(document).ready(function() {
var panel = $("#topnav nav");
var button = $("#hidewrap");
var hiddenClass = "hidden";
var visibleText = $("#hidewrap a span").text(); //"Hide";
var hiddenText = "Show";
var textChange = $("#hidewrap a span");
var classAdd = $("aside#topnav");
button.click(function(e) {
var visibleText = $("#hidewrap a span").text();
var dynText = textChange.text() == visibleText ? hiddenText : visibleText;
hiddenText = textChange.text();
e.preventDefault();
e.stopImmediatePropagation();
textChange.text(dynText);
classAdd.toggleClass(hiddenClass);
panel.slideToggle("fast");
});
});