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

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我這里設(shè)置的取消按鈕是無效的呢?

<style>

? ? body{ font-size:16px;}

? ? .one{

border:1px solid #eee;

width:230px;

height:50px;

background:#ccc;

color:red;

? ? }


</style>

</head>

<body>

? ? <p id="p1"> JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>

? ? <input type="button" value="添加樣式" onclick="add()"/>

? ??

? ? <input type="button" value="取消設(shè)置" onclick="quxiao()"/>


<script type="text/javascript">

? function add(){

? ? ?var p1 = document.getElementById("p1");

? ? ?p1.className="one";

? }

//定義取消設(shè)置?

? ? ? function quxiao(){

? ? ? ? var a = document.getElementById("p1");

? ? ? ? var qx=confirm("是否取消");

? ? ? ? if(qx==true){

? ? ? ? a.removeAttribute('style');?

? ? }

}

</script>


正在回答

4 回答

a.removeAttribute('class');因為它沒有style,只有class,你的style是通過class添加的

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

?a.removeAttribute('style');?這句是無效的,改為?a.className="";。

因為?var a = document.getElementById("p1");而<p id="p1">中并無style屬性。

樣式的添加是通過給對象的className屬性賦值實現(xiàn)的,要取消樣式就要通過給className賦值為空。

如果樣式添加是通過setAttribute("style","color:red")方法實現(xiàn)的,removeAttribute('style')就起作用了。當(dāng)然由于setAttribute()方法存在兼容性問題,很少用這種方法實現(xiàn)樣式添加。

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

? a.removeAttribute('style');?這句有問題吧,換成a.className="";?? 就可以了,我也不知道為什么

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

我也不懂。。。。

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

舉報

0/150
提交
取消

為什么我這里設(shè)置的取消按鈕是無效的呢?

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

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

幫助反饋 APP下載

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

公眾號

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