下面的 jQuery 函数工作正常,并添加了 full
类到 <body>
/signin/
上的 HTML 元素基于 URL 的页面。
// add full class to sign in page body based on url
$(function() {
var loc = window.location.href; // returns the full URL
if(/signin/.test(loc)) {
$('body').addClass('full');
}
});
我想在首页/主页或/
上完成完全相同的事情此同一函数中的 URL。我该怎么做?
最佳答案
正则表达式很慢。更快的方法:
function() {
var loc = window.location.pathname; // returns the pathname
if(loc == '' || loc == '/') {
$('body').addClass('full');
}
});
关于javascript - 如何使用 jQuery 将正文类添加到首页和内部页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39280527/