Javascript条件-不隐藏ID
Javascript Condition - Not hiding ID
我正在尝试隐藏ID"隐藏主页",它总体上正常工作,除了我想将其隐藏在指定URL的第二个条件(http://wgzrv.ndxva.servertrust.com/login.asp)。我是不是错过了什么?
<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>
EDIT(我删除了内部功能,第一次没看到):
<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>
相关文章:
- 使用类而不是id在JavaScript中隐藏显示
- Bootstrap使用复选框显示和隐藏id
- 使用网格ID隐藏剑道网格工具栏
- JS在隐藏未定义的值后仅从数组中返回第一个id的值
- 在代码隐藏 (asp.net VB) 中返回“完整”客户端 ID
- 使用 JQuery 隐藏没有数据(包括标头)且具有相同表 ID 的列
- 使用AJAX发送隐藏的ID输入字段
- 无法访问字段'通过aspx页面上的javascript函数传递来自代码隐藏中函数调用的客户端id的s值(页面加载
- jQuery-如何从同一类中隐藏的输入id中获取不同的值
- Javascript条件-不隐藏ID
- 如何根据给定的 ID 隐藏和显示信息
- 具有一个#id的多选选项可显示n个隐藏表
- 指向“”的超链接;隐藏的“;jQuery Toggler内部的内容(特定的#id)
- 如何从URL隐藏ID
- 单击功能时切换隐藏ID,再次切换功能时显示
- 如何使用自动完成jquery放置隐藏id
- 如何隐藏#id对象
- 隐藏id大于$number的行
- 通过jquery动态隐藏id
- 是否可以在某些浏览器中隐藏id元素