第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

無法清除樣式,請(qǐng)問哪里出錯(cuò)了

<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>className屬性</title>
<style>
????body{?font-size:16px;}
????.one{
????????border:1px?solid?#eee;
????????width:230px;
????????height:50px;
????????background:#ccc;
????????color:red;
????}
????.two{
????????border:1px?solid?#ccc;
????????width:230px;
????????height:50px;
????????background:#9CF;
????????color:blue;
????}
????</style>
</head>
<body>
????<p?id="p1"?>?JavaScript使網(wǎng)頁(yè)顯示動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
????<input?type="button"?value="添加樣式"?onclick="add()"/>
????<p?id="p2"?class="one">JavaScript使網(wǎng)頁(yè)顯示動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
????<input?type="button"?value="更改外觀"?onclick="modify()"/>
????<input?type="button"?value="清除樣式"?onclick="clean()"/>
????<script?type="text/javascript">
???????function?add(){
??????????var?p1?=?document.getElementById("p1");
??????????p1.className?=?"one";
???????}
???????function?modify(){
??????????var?p2?=?document.getElementById("p2");
??????????p2.className?=?"two";
???????}
???????function?clean(){
?????????var?deletestyle?=?confirm('是否清除樣式')
?????????if(deletestyle?==?true){
?????????????document.getElementById("p2").removeAttribute("style");
?????????}
????????else{
????????????alert("啥都不做");
????????}
???????}
????</script>
</body>
</html>


正在回答

5 回答

removeAttribute()方法用來刪除指定的屬性,是.style的,在<style></style>標(biāo)簽里面改的樣式好像重置不了

不知道是不是這樣

2 回復(fù) 有任何疑惑可以回復(fù)我~
#1

烜烜 提問者

http://www.w3school.com.cn/tiy/t.asp?f=jsref_element_removeattribute 我看了一下W3C,是這樣說的: removeAttribute() 方法刪除指定的屬性。 此方法與 removeAttributeNode() 方法的差異是:removeAttributeNode() 方法刪除指定的 Attr 對(duì)象,而此方法刪除具有指定名稱的屬性。結(jié)果是相同的。同時(shí)此方法不返回值,而 removeAttributeNode() 方法返回被刪除的屬性,以 Attr 對(duì)象的形式。
2016-01-23 回復(fù) 有任何疑惑可以回復(fù)我~
#2

烜烜 提問者

非常感謝!
2016-01-26 回復(fù) 有任何疑惑可以回復(fù)我~

樓主我知道了 ,在<style></style>標(biāo)簽里面改的樣式是清除不了的,可是你知道怎么改嗎

0 回復(fù) 有任何疑惑可以回復(fù)我~

請(qǐng)問樓主這個(gè)問題如何解決啊,我也是有這個(gè)困擾

0 回復(fù) 有任何疑惑可以回復(fù)我~

也許是因?yàn)椤?。?strong>removeAttribute("style"),style的值沒有寫在P1和P2標(biāo)簽里面。是寫在head上面的。所以。我覺得可以這樣寫

function clean(){

? ? ? ? ?var deletestyle = confirm('是否清除樣式')

? ? ? ? ?if(deletestyle == true)

? ? ? ? ?{

? ? ? ? ? ? ?p1.className = "";

? ? ? ? ? ? ?p2.className = "one";

? ? ? ? ?}

? ? ? ? else{

? ? ? ? ? ? alert("啥都不做");

? ? ? ? }


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

烜烜 提問者

也就是說removeAttribute("style"),能清除行內(nèi)樣式,不能清除內(nèi)聯(lián)樣式吧:)
2016-01-23 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

無法清除樣式,請(qǐng)問哪里出錯(cuò)了

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)