请教下,用javascript如何才能取得上层文件夹名称?
例如:
http://www.xxx.com/products/index.html
在当前页面中我想取到products.http://www.xxx.com/news/index.html
在当前页面中我想取到news.
例如:
http://www.xxx.com/products/index.html
在当前页面中我想取到products.http://www.xxx.com/news/index.html
在当前页面中我想取到news.
alert(xx[xx.length - 2]);
例如:
http://www.xxx.com/products/index.html
在当前页面中我想取到products.http://www.xxx.com/news/index.html
在当前页面中我想取到news.
--------------
我想实现这样的效果:
如果javascript取得的值是product,http://www.xxx.com/products/index.html菜单栏的"product"下的背景颜色为红,其他为白;如果javascript取得的值是news,http://www.xxx.com/news/index.html菜单栏的"news"下的背景颜色为红,其他为白.
不能直接设置背景颜色,因为这个菜单栏位都是动态的.这个如何写?
<script>
...
</script>
就是定义一个方法,在菜单栏的地方调用这个方法??
#menu li.menuon {background-color:#ff0000;}
html..........<div id="menu">
<ul>
<li id="index">首页</li>
<li id="news">新闻</li>
<li id="porducts">产品</li>
</ul>
</div><script>
var ar = window.location.herf.split("\");
var on = ar[ar.length - 2];
document.getElementById(on).className = "menuon";
</script>
现在关键是没有这样的列表显示:
<li id="index">首页</li>
<li id="news">新闻</li>
<li id="porducts">产品</li>
--------------
没有相对应的id,就是一个标签读出来的.
<style>
.pp{background-color:#cc0000}
</style>
<script>
var uu=window.location.href.split("/");
var s=uu[2];
//alert(s);
if (s="product"){
document.getElementById("temptest").style="pp";
</script>
...
<li id="temptest">...</li>
这个怎么不起作用?
就算起了作用,也是把整个栏位的背景色都设置为了红色,如何设置单独的某个菜单栏的背景色为红色呢?
其他的为白色?
就是点了product栏位时才显示背景颜色...
------
谢谢各位了,一直在线