【问题标题】:Changing background color in specific html page with jquery使用 jquery 更改特定 html 页面中的背景颜色
【发布时间】:2014-10-02 10:57:22
【问题描述】:

我想更改单个 HTML 页面(例如 contact.html)的背景颜色,但不使用 jquery 更改其他页面的颜色。可能我必须创建一个 if 语句才能检查 url 并更改颜色,但我找不到方法。

提前谢谢你。

【问题讨论】:

  • 请输入一些代码以了解您在说什么以及如何应用 jquery 功能

标签: jquery html css


【解决方案1】:

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

这样你可以检查脚本当前在哪个页面运行:

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的解决方案

【讨论】:

    猜你喜欢
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多