課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
麻煩看一下
2021-07-25
源自:JavaScript入門篇 3-6
正在回答
<body>
? ? <p id="p1" > JavaScript使網(wǎng)頁顯示動態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
? ? <input type="button" value="添加樣式" onclick="add()"/>
<p id="p2" class="one">JavaScript使網(wǎng)頁顯示動態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
? ? <input type="button" value="更改外觀" onclick="modify()"/>
<script type="text/javascript">
? ?function add(){
? ? ? var p1 = document.getElementById("p1");
? ? ? p1.className = "one";
? ?}
? ?function modify(){
? ? ? var p2 = document.getElementById("p2");
? ? ? p2.className = "two";
? ? ? alert("更改后P2的Class值為: " + p2.className);
</script>
</body>
//試試這個,看看是不是兄弟要的效果?
上面問題的結(jié)果
weixin_慕容1333430
慕UI5008586 回復(fù) weixin_慕容1333430
舉報
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
4 回答怎么樣能讓“點(diǎn)擊更改”后“p元素class值為:one”變?yōu)閠wo?
4 回答為什么點(diǎn)擊按鈕后的“p元素class值為:one",點(diǎn)擊后不是變成"two"了嗎
4 回答為什么按了更改外觀的按鈕,"p2元素class的值為”不會變成two?怎樣才能達(dá)到效果?
3 回答為什么加了 function modify(){ var p2 = document.getElementById("p2"); // document.write("p元素的class值為:"+p2.className+"<br/>"); p2.className="two"; }之后就能改變樣式了
2 回答className修改了p1,p2標(biāo)簽為one、two,為什么不是#one、#two?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2022-08-18
<body>
? ? <p id="p1" > JavaScript使網(wǎng)頁顯示動態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
? ? <input type="button" value="添加樣式" onclick="add()"/>
<p id="p2" class="one">JavaScript使網(wǎng)頁顯示動態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
? ? <input type="button" value="更改外觀" onclick="modify()"/>
<script type="text/javascript">
? ?function add(){
? ? ? var p1 = document.getElementById("p1");
? ? ? p1.className = "one";
? ?}
? ?function modify(){
? ? ? var p2 = document.getElementById("p2");
? ? ? p2.className = "two";
? ? ? alert("更改后P2的Class值為: " + p2.className);
? ?}
</script>
</body>
//試試這個,看看是不是兄弟要的效果?
2021-07-25
上面問題的結(jié)果