首页和栏目页用的是相同的网页模板,为了区分,想通过javascript 实现这样的功能:
当打开首页. 把id="box1" 的DIV层自动隐藏.
当url不是首页地址的时候, 把id="box2"的DIV层隐藏.例如.当url为http://www.abc.com/ 时,自动隐藏<DIV id="box1"></DIV> 标签内的页面内容.<DIV id="box2"></DIV> 正常显示.当url为http://www.abc.com/abc等,自动隐藏<DIV id="box2"></DIV> 标签内的页面内容.<DIV id="box1"></DIV> 正常显示.
<html>
<body>
<div id="box1">
box1
</div>
<div id="box2">
box2
</div><script type="text/javascript">
function disPlay(){
var b1 = document.getElementById("box1");
var b2 = document.getElementById("box2");
if(window.location.href = "http://www.abc.com/"){
b1.style.display = "none";
b2.style.display = "block"
}
else{
b1.style.display = "block";
b2.style.display = "none"
}
}
</script>
</body>
</html>
二楼的,按上面的代码, 调试不出来啊,
当打开首页. 把id="box1" 的DIV层自动隐藏.
当url不是首页地址的时候, 把id="box2"的DIV层隐藏.例如.当url为http://www.abc.com/ 时,自动隐藏<DIV id="box1"></DIV> 标签内的页面内容.<DIV id="box2"></DIV> 正常显示.当url为http://www.abc.com/abc等,自动隐藏<DIV id="box2"></DIV> 标签内的页面内容.<DIV id="box1"></DIV> 正常显示.
<html>
<body>
<div id="box1">
box1
</div>
<div id="box2">
box2
</div><script type="text/javascript">
function disPlay(){
var b1 = document.getElementById("box1");
var b2 = document.getElementById("box2");
if(window.location.href = "http://www.abc.com/"){
b1.style.display = "none";
b2.style.display = "block"
}
else{
b1.style.display = "block";
b2.style.display = "none"
}
}
</script>
</body>
</html>
二楼的,按上面的代码, 调试不出来啊,
解决方案 »
- readonly只读的问题,很急!!
- 一个简单的js定时切换选项卡问题
- JS组织结构图(子节点三个以下不出错,子节点四个以上就出错了)
- js cookies 关于访客来路记录的问题
- 动态生成div将div设置为inline怎么没有效果?
- 层拖拽效果的一点问题,高分求,大家看看啊!!
- 请教高手,如何使用js通过浏览器获得客户机的信息
- 采用hyperlinkcolumntanchu.弹出新窗口后,原页面变为空白,仅有[Object],
- ◆◆◆◆◆◆◆◆◆紧急发问:关于长度验证的问题
- index.jsp无法识别
- var matchExp ="^http[s]?:\\/\\/([ \\w-]+\\.)+[\\w-]+...";
- 100分求一时间算法
window.location.href == "http://www.abc.com/"最好是
if(window.location.href.toString().indexOf('http://www.abc.com/') > -1)
<body onload="disPlay()">
还又其他方法调用的没?
window.onload = function(){
disPlay();
}