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
}