function nav(name, csskey,cssvalue) {
var url = window.location.pathname + window.location.search;
var v1 = "";
$(name).each(function () {
v1 = "/" + $(this).attr("href");
if (v1 == url) {
var v2 = $(this).css(csskey, cssvalue);
}
})
var url = window.location.pathname + window.location.search;
var v1 = "";
$(name).each(function () {
v1 = "/" + $(this).attr("href");
if (v1 == url) {
var v2 = $(this).css(csskey, cssvalue);
}
})
}
//用法
<script src="Scripts/commo.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
nav(".top ul li a", "background-color", "rgb(255,89,0)");
}
</script>
本文展示了一个使用JavaScript实现的动态样式切换功能,通过遍历指定元素并根据当前URL匹配来改变元素样式。
304

被折叠的 条评论
为什么被折叠?



