我需要在兩種顏色之間閃爍:紅色和白色。jQuery不同瀏覽器的標準顏色定義是什麼?
我發現$targetcss('background-color','red')
後,
的$targetcss('background-color')
值是不是紅色,而是rgb(255, 255, 255)
,
講究,有之間的空間 「」 和數字在Firefox中,
但IE中沒有空間。
我的代碼現在:
if(existingBgColor != 'rgb(255, 255, 255)')
$target.css('background-color', 'rgb(255, 255, 255)');
else
$target.css('background-color', 'white');
在Firefox其中一期工程,但沒有對IE瀏覽器。
當然,我可以把它改成這樣,使之適用於IE:
if(existingBgColor != 'rgb(255, 255, 255)' && existingBgColor != 'rgb(255,255,255)')
$target.css('background-color', 'rgb(255, 255, 255)');
else
$target.css('background-color', 'white');
但是什麼第三瀏覽器嗎?
有沒有標準的解決方案呢?
事實上,我期待使用某種方式來使用「紅色」,「白色」等顏色,但似乎現在是快速修復。 – omg
不好的選擇。 JavaScript中的正則表達式很慢。使用HEX(看看我的答案)。 – roosteronacid
10-20個字符長度的字符串的正則表達式不慢。它不可能。你的回答並沒有回答他的問題,因爲他正在尋找方法來檢查rgb值。你給了他另一個選擇。 – peirix