您可以使用
window.location获取当前URL,然后基于该URL进行切换:
$(function() { var loc = window.location.href; // returns the full URL if(/technology/.test(loc)) { $('#main').addClass('tech'); }});它使用正则表达式查看URL是否包含特定短语(特别是
technology),如果包含,则将一个类添加到该
#main元素。

您可以使用
window.location获取当前URL,然后基于该URL进行切换:
$(function() { var loc = window.location.href; // returns the full URL if(/technology/.test(loc)) { $('#main').addClass('tech'); }});它使用正则表达式查看URL是否包含特定短语(特别是
technology),如果包含,则将一个类添加到该
#main元素。