Javascript条件 - 不隐藏ID

我试图隐藏ID“隐藏主页”,它的整体工作,除了我的第二个条件,我想隐藏它在所述的URL(http://wgzrv.ndxva.servertrust.com/login.asp)。我错过了什么吗?Javascript条件 - 不隐藏ID

<script type="text/javascript">  

$(window).resize(function(){

function showMyDiv() {

if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) {

document.getElementById("hide-homepage").style.display="none";

} else if (window.location.href == "http://wgzrv.ndxva.servertrust.com/login.asp") {

document.getElementById("hide-homepage").style.display="none";

} else if (document.documentElement.clientWidth < 992) {

document.getElementById("hide-homepage").style.display="none";

} else {

document.getElementById("hide-homepage").style.display="block";

}

}

});

</script>

回答:

if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) { 

应该

if (window.location.href == "http://wgzrv.ndxva.servertrust.com" && document.documentElement.clientWidth > 992) { 

回答:

尝试,而不是使用的indexOf()==

<script type="text/javascript">  

$(window).resize(function(){

function showMyDiv() {

if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) {

document.getElementById("hide-homepage").style.display="none";

} else if (window.location.href.indexOf("http://wgzrv.ndxva.servertrust.com/login.asp") > -1) {

document.getElementById("hide-homepage").style.display="none";

} else if (document.documentElement.clientWidth < 992) {

document.getElementById("hide-homepage").style.display="none";

} else {

document.getElementById("hide-homepage").style.display="block";

}

}

});

</script>

编辑(我删除了内部函数,没有看到它的第一时间):

<script type="text/javascript">  

$(window).resize(function(){

if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) {

document.getElementById("hide-homepage").style.display="none";

} else if (window.location.href.indexOf("http://wgzrv.ndxva.servertrust.com/login.asp") > -1) {

document.getElementById("hide-homepage").style.display="none";

} else if (document.documentElement.clientWidth < 992) {

document.getElementById("hide-homepage").style.display="none";

} else {

document.getElementById("hide-homepage").style.display="block";

}

});

</script>

以上是 Javascript条件 - 不隐藏ID 的全部内容, 来源链接: utcz.com/qa/266270.html

回到顶部