我正在操纵jquery mobile中的嵌套列表。我需要检查url是否以x#&ui-page=globalMenu-"and a number“结尾。我该怎么做呢?
表示url的ex
www.test.no/Site/default.aspxx#&ui-page=globalMenu-7我想检查站点是否结束/包含#&ui-page=globalMenu
发布于 2012-01-20 00:04:56
尝尝这个。
if(location.hash.indexOf('&ui-page=globalMenu') != -1){
//It ends with #&ui-page=
}发布于 2012-01-20 00:08:19
window.location.hash将为您提供#&ui-page=globalMenu-7访问权限。
因此,下面的代码将执行您想要的操作:
var matches = window.location.hash.match(/#\&ui-page=globalMenu\-([0-9])?/);对于您给出的示例:
matches[0]将包含:#&ui-page=globalMenu-7
matches[1]将包含:7
发布于 2012-01-20 00:04:14
只需检查window.location.hash的值是否与所需的字符串相等。
示例:
网址:http://stackoverflow.com/questions/8929224/jquery-if-url-window-location-pathname-ends-with-ui-page/8929249#8929249
window.location.hash的值:#8929249
https://stackoverflow.com/questions/8929224
复制相似问题