亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

為什么我用removeAttribute("style")來恢復樣式不行呢,

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">

<title>讓我們互動下</title>

<style type="text/css">

P{

border:1px solid red;

background:gray;

width:100px;

height:30px;

text-align:center;

line-height:30px;

}

.one{

? border:2px solid blue;

? background:yellow;

? width:200px;

? height:50px;

? line-height:50px;

}

.two{

border:3px dashed yellow;

background:purple;

width:300px;

height:300px;

line-height:300px;

}

</style>

<script type="text/javascript">


function rec(){

var message=confirm("關注JS進階篇");

if (message==true)?

{

document.write("希望你學有所成");

}?

else?

{

document.write("希望你能關注一下");

}

}

</script>

</head>

<body>

<p id="con">JS進階篇</p>

<form>

<input type="button" name="button" onclick="rec()" value="點擊我試試" />

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

<input type="button" onclick="change()" value="改變樣式" />

<input type="button" name="button" onclick="resetcss()" value="重置樣式" />

</form>

<script type="text/javascript">

var mychar=document.getElementById("con");

function add(){

mychar.className="one";

}

function change(){

mychar.className="two";

}

function resetcss(){


var message1=confirm("確定要恢復原始設置?");

if (message1==true)?

{


mychar.removeAttribute("style");

}?

}

</script>

</body>

</html>


正在回答

5 回答

mychar.removeAttribute("style");//這里移除的style是節點里面聲明的style,而不能移除className所帶來的css樣式,假如<p id="con" style=“color:red;”>JS進階篇</p> 那么按了重置,red就會沒有。

修改:

mychar.removeAttribute("class");

4 回復 有任何疑惑可以回復我~
#1

大塊吃肉188 提問者

非常感謝!
2016-12-18 回復 有任何疑惑可以回復我~

? ? //mychar.removeAttribute("class");

? ? mychar.classList.remove("one"&&"two");

這兩句都可以的

0 回復 有任何疑惑可以回復我~

style用單引號試試

0 回復 有任何疑惑可以回復我~

你把 if else 語句補完整試試?

0 回復 有任何疑惑可以回復我~

你吧style煥成單引號試試 ?''

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么我用removeAttribute("style")來恢復樣式不行呢,

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號