我認爲自CSS 3
可以使用Background
作爲Background-color
屬性。它說顯示的顏色是基於Desktop-Color的,所以它可以從客戶端到客戶端變化。 alert(document.body.style.backgroundColor);
僅返回background
,而不是顏色值。 那麼如何獲取特定元素中使用顏色的RGB-/Hex-Value?如何在JavaScript中獲取「背景顏色:背景」顏色?
-1
A
回答
1
// $0 is your htmlElement
window.getComputedStyle($0, null).getPropertyValue('background-color')
+1
現代瀏覽器不需要'null' – Oriol
+0
@Oriol很高興知道,無論如何,我爲了兼容性,我將把它留在那裏 –
相關問題
- 1. UITableView:獲取背景顏色
- 2. 背景或背景顏色?
- 3. 背景顏色
- 4. 背景顏色
- 5. 背景顏色
- 6. 背景顏色
- 7. 顏色背景
- 8. CSS3PIE背景褪色背景顏色
- 9. 如何改變背景顏色和背景顏色?
- 10. 如何獲取WPF背景的顏色
- 11. 如何獲取TextView的背景顏色?
- 12. 如何獲取CheckBox背景顏色
- 13. 如何用背景圖像爲背景顏色重新添加背景顏色?
- 14. 在數組中獲取背景顏色?
- 15. 在cocos2d/IOS中獲取背景顏色
- 16. Javascript改變背景顏色
- 17. Javascript變暗背景顏色
- 18. Android獲取父視圖的背景顏色,如果沒有背景顏色集
- 19. Uipicker背景顏色
- 20. NSImageView +背景顏色
- 21. DBVisualizer背景顏色
- 22. 背景顏色,ForegroundColor
- 23. QSciScintilla背景顏色
- 24. 1背景顏色
- 25. 背景顏色行
- 26. Win32背景顏色
- 27. FieldSet背景顏色
- 28. ItemControl背景顏色
- 29. DataGridViewTextBoxEditingControl背景顏色
- 30. iframe背景顏色
您能得到什麼,如果你使用的getComputedStyle'()'? – Barmar
document.body.style.backgroundColor對我來說很好用 –
'backgroundColor'返回背景顏色,而不是整個背景。並且'background-color'已經在CSS 2.1 – Oriol