2009-04-27 159 views
64

jQuery的突出显示方法将突出显示任何具有黄色背景的div。更改突出显示的颜色

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

回答

127

按照documentation

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

只是想知道,我将如何突出显示仅文本,而不是背景? – think123 2012-12-13 09:42:57

+1

在这个答案中给出的例子很容易理解,不像上面链接到上面的那个用于“突出”效果的页面文档,而且非常稀疏。有关.effect()本身的更多详细信息,请参阅此页面:http://api.jqueryui.com/effect/。 – 2014-02-25 08:08:28

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

会以红色突出显示。全部在documentation

+1

color =会给出语法错误。符号是关键:'值' – 2009-04-27 22:53:05

3

FWIW我发现当jQuery 1.7.2使用effect("highlight",...)时,当元素的当前颜色被指定为文本或突出显示颜色被指定为文本(即"blue")而不是以十六进制表示法时: "#ff0000"

1
 $('.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"); 

     } 
     }); 

这将给不透明外观带来不错的悬停效果。

相关问题