2014-10-02 99 views
-2

我想更改单个HTML页面(例如contact.html)的背景颜色,但不更改jQuery其他页面的颜色。显然,我必须使如果声明为了检查URL和更改颜色,但我无法找到如何。用jquery更改特定html页面中的背景颜色

预先感谢您。

+1

请把一些代码来知道你在说些什么,以及如何你申请了jQuery功能 – 2014-10-02 10:59:44

回答

0

我猜你在所有页面中都使用相同的脚本?

这种方式,你可以查阅一下页面的脚本正在运行中:

if (document.location.pathname.match(/[^\/]+$/)[0] == 'contact.html') { 
    //... do what ever you only want to do if it's contact.html 
    $('body').css("background-color", "yellow"); 
} 

解决方案从Jquery to get the name of the current html file