【发布时间】:2014-07-28 07:45:53
【问题描述】:
我正在像这样与 jQuery 建立活动链接
$(document).ready(function() {
var url = window.location.href;
$(".main-navigation ul li a").each(function() {
var $this = $(this);
var href = $this.attr("href");
if (url === href) {
$this.css({
'color': '#666666',
'font-weight': 'bold',
}).addClass('active').removeAttr("href").removeAttr("onclick");
}
});
唯一的问题是我的 a href 是这样的 /Settings/File?id=333
网址会是这样的
http://www.example.com/Settings/File?id=333
那么a href和ulr不匹配,如何删除url的http和example并用a href检查?
【问题讨论】:
-
不确定我们是否可以用 $this 代替 $(this)
-
一切正常,问题出在example.com