日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

html title属性无效_【学习教程】使用JavaScript删除CSS属性

發(fā)布時(shí)間:2023/12/10 javascript 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html title属性无效_【学习教程】使用JavaScript删除CSS属性 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
方法1:使用CSS removeProperty:該CSSStyleDeclaration.removeProperty()方法被用來(lái)從一個(gè)元件的樣式刪除一個(gè)屬性。通過(guò)遍歷styleSheets數(shù)組并選擇cssRule,可以選擇元素的樣式。然后可以使用要?jiǎng)h除的屬性指定removeProperty方法。句法:element.removeProperty('property')實(shí)例1: <html> <head> <title> How to remove CSS property using JavaScript? title> <style> .elem { color: green; font-size: 3rem; text-decoration: underline; } style> head> <body> <h1 style="color: green"> GeeksForGeeks h1> <b> How to remove CSS property using JavaScript? b> <div class="elem">Hello World!div> <p> Click on the button below to remove the text decoration of the element p> <button onclick="removeProperty()"> Remove text-decoration property button> <script> function removeProperty() { element = document.styleSheets[0].cssRules[0].style; element.removeProperty('text-decoration'); } script> body> html> 輸出:在單擊按鈕之前:單擊按鈕后:方法2:使用setProperty方法:該CSSStyleDeclaration.setProperty()方法可用于設(shè)置的樣式的所需的屬性。選擇必須刪除其屬性的元素,并將此屬性應(yīng)用于其style屬性。將此屬性設(shè)置為“ initial”可將屬性重置為其初始值,從而消除該屬性的任何影響。句法:element.style.setProperty('color','initial')例如: <html> <head> <title> How to remove CSS property using JavaScript? title> <style> .elem { color: green; font-size: 3rem; text-decoration: underline; } style> head> <body> <h1 style="color: green"> GeeksForGeeks h1> <b> How to remove CSS property using JavaScript? b> <div class="elem">Hello World!div> <p> Click on the button below to remove the text color of the element p> <button onclick="removeProperty()"> Remove color property button> <script> function removeProperty() { element = document.querySelector('.elem'); element.style.setProperty('color', 'initial'); } script> body> html> 輸出:
  • 在單擊按鈕之前:

單擊按鈕后:本文完~

免責(zé)申明:本站所有內(nèi)容均來(lái)自網(wǎng)絡(luò),我們對(duì)文中觀點(diǎn)保持中立,對(duì)所包含內(nèi)容的準(zhǔn)確性,可靠性或者完整性不提供任何明示或暗示的保證,請(qǐng)僅作參考。若有侵權(quán),請(qǐng)聯(lián)系刪除。

總結(jié)

以上是生活随笔為你收集整理的html title属性无效_【学习教程】使用JavaScript删除CSS属性的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。