JS設置css樣式的幾種方式


/* 1.直接設置style屬性 */
element.style.height = '100px';
 
/* 2.直接設置屬性 */
element.setAttribute('height', '100px');
 
/* 3.使用setAttribute設置style屬性 */
element.setAttribute('style', 'height: 100px !important');
 
/* 4.使用setProperty設置屬性,通過第三個參數設置important */
element.style.setProperty('height', '300px', 'important');
 
/* 5.設置cssText */
element.style.cssText += 'height: 100px !important';


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM