此脚本非常适合将“criminal”类添加到此页面名为“h1_wrapper”的 div 中:
if(window.location.pathname == '/Criminal-Law-Blog') {$( ".h1_wrapper" ).addClass( "criminal" );
当我点击特定的博客条目时,它会添加到路径名中;例如:
/Criminal-Law-Blog/2014/11/Criminal-Law-Blog-Test-Entry-1
如何编辑代码以使该类添加到“/Criminal-Law-Blog”后面的任何路径?我知道这可能很容易,但我就是想不通!
提前致谢!
最佳答案
最简单的方法是执行 window.location.pathname.match(/^\/Criminal-Law-Blog/)
关于javascript - 根据路径名向元素添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27241248/