繁体   English   中英

使用JavaScript检查链接变量

[英]Check link variable with JavaScript

以如下页面为例:

http://www.example.com/Page.asp?Page=About

使用JavaScript,如何检查窗口的位置是否包含?Page=About

这是我到目前为止的代码,但似乎无法正常工作。

$(document).ready(function(){
if ($(window.location:contains('?Page=About')").length !== 0) 
{
alert("Currently on About page");
}
else {
}
});

请帮忙 :)

谢谢

使用.indexOf()代替contains

if ( window.location.href.indexOf('?Page=About') > -1) 

window.location包含Location对象.. href属性保存url

检查小提琴

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM