我想要獲得動態設置的所有樣式(它適用於內聯樣式)。如何在jQuery中獲取所有動態設置的內聯樣式CSS?
例如
<span class="text" style="color: rgb(128, 128, 255); font-size: 24px;">Name</span>
我想樣式屬性的一個JS變量的值,並將其保存。 我已經使用jQuery的.attr(「風格」)試過了,但它給不確定
此外,由於這裏建議How to get inline CSS style property from element使用
getComputedStyle
,但得到的風格,我需要提到的所有風格如
var el = document.querySelector("selector")
console.log(el.style.SomeStyle);
但有各種樣式,用戶可以動態設置。 那麼,我是否需要單獨提及所有聯機風格或者是否有更好的方法來獲取?
預先感謝任何幫助
從void's評論更新:
如這裏所描述Can jQuery get all CSS styles associated with an element?
marknadal曾寫道,檢索內嵌和外部樣式的功能,但我只是不管連接的所有css類如何,都需要內聯樣式
https://stackoverflow.com/questions/754607/can-jquery-get-all-css-styles-associated-with-an-element – void