2009-04-27 135 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"); 

     } 
     }); 

這將給不透明外觀帶來不錯的懸停效果。

相關問題