jQuery 更改高亮颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/795600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:48:23  来源:igfitidea点击:

Change highlight color

jqueryjquery-ui

提问by Hady

jQuery's highlight method will highlight any div with a yellow background.

jQuery 的 highlight 方法将高亮任何带有黄色背景的 div。

How do I specify what color to use instead of yellow for highlight?

如何指定使用什么颜色而不是黄色来突出显示?

回答by Paolo Bergantino

According to the documentation:

根据文档

$(this).effect("highlight", {color: 'blue'}, 3000);

回答by Tomas Aschan

$("div").click(function () {
    $(this).effect("highlight", { color: "#ff0000" }, 3000);
});

will highlight in red. It's all in the documentation.

将以红色突出显示。这一切都在文档中

回答by saschwarz

FWIW I found that IE8 would give an error in jQuery 1.7.2 usingeffect("highlight",...)when the current color of the element was specified as text or when the highlight color was specified as text (i.e. "blue") instead of in hex notation: "#ff0000".

FWIW我发现,IE8将给予使用jQuery的1.7.2的错误effect("highlight",...)时,该元素的当前颜色被指定为文本或当高亮颜色被指定为文本(即"blue"),而不是16进制:"#ff0000"

回答by Usman Younas

       $('.divID').live('mouseover mouseout', function (event) {
        if (event.type == 'mouseover') {
            // do something on mouseover
          $(this).css({ "background-color": YOURCOLOR, "opacity": ".50" });

        }
        else {
            // do something on mouseout
             $(this).css("opacity", "100");

        }
      });

This will give the nice hover effect with opacity looks.

这将提供具有不透明外观的漂亮悬停效果。