【发布时间】:2015-05-11 02:48:44
【问题描述】:
我这里有问题。我想在我的网站上隐藏一个内容并使用 jQuery 显示下一个内容。我只有 2 个内容 div。
所以基本上我想做的是......
1) 当我打开网站<div id="content2"></div> 和<div id="content2_bottom"></div> 时隐藏。
2) 当我点击链接 <a href="#" id="click_to_change_content">Click</a> ...<div id="content1"></div> 和 <div id="content1_bottom"></div> 隐藏并且 content2 可见。
我的代码:
$(function(){
if ($("#content1").is(":visible")) {
$("#content2").hide();
$("#content2_bottom").hide();
}
$("#click_to_change_content").on("click", function(){
$("#content1").hide();
$("#content2").show();
$("#content1_bottom").hide();
$("#content2_bottom").show();
});
});
它实际上是交换内容,但它会立即交换它,所以我一直只看到 content1。我确定我有什么不好的地方,但我只是 jQuery 的初学者,所以我不知道我做错了什么。
感谢您的建议!
【问题讨论】:
标签: javascript jquery html css visibility