我试图查看菜单中是否存在指向当前页面URL的链接.
var thisUrl = window.location.href;
$("ul.leftmenu li a").each(function() {
var thisHref = $(this).attr('href');
if (thisUrl === thisHref) {
// matches
}
});
Run Code Online (Sandbox Code Playgroud)
只要当前窗口位置URL不包含任何_GET变量,此方法就可以正常工作.我如何修改它以忽略当前地址中的_GET变量?
您可以从中删除查询字符串部分href.例如这样:
var thisUrl = window.location.href.replace(location.search, '');
Run Code Online (Sandbox Code Playgroud)
location.searchproperty表示GET参数substring,即?param=value¶m2=etc.
| 归档时间: |
|
| 查看次数: |
168 次 |
| 最近记录: |