2013-05-07 38 views
0

試圖八九不離十檢查與jQuery的右邊框的顏色值,像這樣:檢查CSS顏色與jQuery

if ($(this).css("border-right-color") == "#000") { 
    // Do some magic 
} 

但是,這並不工作。 console.log ing()$(this).css(「border-right-color」)的值表示rgb(0,0,0)

那麼,我該如何編寫這個條件檢查?

+1

用的''而不是RGB(0,0,0,0)比較'#000'? – bfavaretto 2013-05-07 23:12:19

+0

你期待什麼顏色? – Jivings 2013-05-07 23:15:03

+0

rgb()不是沒有一種對象。 – Wells 2013-05-07 23:15:11

回答

0

使用下面這個函數發現here

if (rgb2hex($(this).css("border-right-color")) == "#000") { 
    // Do some magic 
} 


function rgb2hex(rgb){ 
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); 
return "#" + 
    ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) + 
    ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) + 
    ("0" + parseInt(rgb[3],10).toString(16)).slice(-2); 
} 

Take a look here for a working example