JS显示/隐藏默认行为 [英] JS show/hide default behavior
本文介绍了JS显示/隐藏默认行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改默认行为,以便仅显示带有电影ID的div内容?
How can I change the default behavior so that ONLY the contents of the div with the id of films is initially shown?
JavaScript:
JavaScript:
window.addEventListener("hashchange", function () {
var targetDiv = $(location.hash);
if (!targetDiv.is(':visible')) {
$('.page').slideUp();
targetDiv.slideDown();
} else {
$('.page').slideUp();
}
}, false);
JS小提琴: http://jsfiddle.net/s9cxjrmf/
我最初尝试将display: none
添加到页面div
,但这根本解决不了我的问题,因为它在开始时隐藏了所有内容,而不是显示所有内容.我需要做的就是仅在页面加载时显示第一个div的内容时保持其功能.
I tried adding display: none
to the page div
initially but that doesn't solve my problem at all since it hides everything at start instead of displaying everything. All I need is to keep its functionality while displaying the first div's content only when the page is loaded.
推荐答案
添加此行
$('#films').show();
在脚本中解决您的问题.
in your script to resolve your issue..
这篇关于JS显示/隐藏默认行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文