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

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

怎么樣能讓“點擊更改”后“p元素class值為:one”變?yōu)閠wo?

<!DOCTYPE html>

<html>

<head>

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

<title>className屬性</title>

<style type="text/css">

input{

font-size: 10px;

}

.one{

width:200px;

background-color: #CCC;

}

.two{

font-size: 18px;

color:#F00;

}

</style>

</head>

<body>

<p id="con" class="one">JavaScript</p>

<form>

<input type="button" name="button" onclick="modifyclass()" value="點擊更改" />

</form>

<script type="text/javascript">

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

document.write("P元素Class值為:"+mychar.className+"<br>");

function modifyclass(){

mychar.className="two";

}

</script>

</body>

</html>


正在回答

4 回答

<!DOCTYPE?html>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html"?charset="utf-8">
<title>className屬性</title>
<style?type="text/css">
input{
font-size:?10px;
}
.one{
width:200px;
background-color:?#CCC;
}
.two{
font-size:?18px;
color:#F00;
}
</style>
</head>
<body>
<p?id="con"?class="one">JavaScript</p>
<p?id="aa"></p>
<form>
<input?type="button"?name="button"?onclick="modifyclass()"?value="點擊更改"?/>
</form>
<script?type="text/javascript">
var?mychar=document.getElementById("con");
var?aa=document.getElementById("aa");
aa.innerHTML=("P元素Class值為:"+mychar.className+"<br>");
function?modifyclass(){
mychar.className="two";
aa.innerHTML=("P元素Class值為:"+mychar.className+"<br>");

}
</script>
</body>
</html>
這是我仿照你之前提的問題,別人給出答案的方式寫的,雖然能實現(xiàn)你說的效果,但我覺得代碼有點冗余


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

大塊吃肉188 提問者

非常感謝!
2016-08-15 回復 有任何疑惑可以回復我~
#2

寶慕林5689754

nice
2019-08-24 回復 有任何疑惑可以回復我~

調(diào)用document.write就是重新打開一個文檔。本來你的這個頁面已經(jīng)加載完畢,然后你在執(zhí)行一個document.write重新打開一個文檔然后輸出,所以你原來的內(nèi)容就會被覆蓋了

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

已經(jīng)改變了啊?先到瀏覽器執(zhí)行看看是不是沒調(diào)用我直接復制你的代碼執(zhí)行沒錯的

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

我試著把document.write("P元素Class值為:"+mychar.className+"<br>");這句放到function modifyclass(){ ?。沁@樣會覆蓋上邊的內(nèi)容

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

舉報

0/150
提交
取消

怎么樣能讓“點擊更改”后“p元素class值為:one”變?yōu)閠wo?

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

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

幫助反饋 APP下載

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

公眾號

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