Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如果Location.Pathname包含_Jquery_Url_Pathname - Fatal编程技术网

Jquery 如果Location.Pathname包含

Jquery 如果Location.Pathname包含,jquery,url,pathname,Jquery,Url,Pathname,我目前正在使用以下代码来针对单个页面,例如 我想知道如何对具有特定父页面的所有页面(如以下示例中的/about/)执行相同的操作 使用indexOf-它将测试所有以/about/ if (document.location.pathname.indexOf("/about/") == 0) { //Code goes here } 这将检查以确保路径名始终以该字符串开头。如果您有兴趣更具体地检查格式,则需要使用regex if (document.location.pathname.

我目前正在使用以下代码来针对单个页面,例如

我想知道如何对具有特定父页面的所有页面(如以下示例中的
/about/
)执行相同的操作


使用indexOf-它将测试所有以
/about/

if (document.location.pathname.indexOf("/about/") == 0) {
    //Code goes here
}
这将检查以确保路径名始终以该字符串开头。如果您有兴趣更具体地检查格式,则需要使用
regex

if (document.location.pathname.indexOf("/about/") == 0) {
    //Code goes here
}
    if (document.location.pathname.indexOf("/about/") === 0) {
        //Code goes here
    }