最后一個重置不能用呢。其他都對的
?<form>
? <!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="cgc()"> ?
? ? <input type="button" value="改變寬高" onclick="hg()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="yc()">
? ? <input type="button" value="顯示內(nèi)容" onclick="xs()">
? ? <input type="button" value="取消設(shè)置" onclick="qx()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù) ?
? ? function cgc(){ var mychar=document.getElementById("txt");
? ? ? ? ? ? ? ? ? ? mychar.style.color="red";
? ? ? ? ? ? ? ? ? ? mychar.style.backgroundColor="#ccc";}
? ? ? ? ? ? ? ? ? ??
//定義"改變寬高"的函數(shù)
? ? function hg(){ ?var mychar=document.getElementById("txt");?
? ? ? ? ? ? ? ? ? ? mychar.style.width="300px";}
? ??
//定義"隱藏內(nèi)容"的函數(shù)
? ? function yc(){ ?var mychar=document.getElementById("txt");
? ? ? ? ? ? ? ? ? ? mychar.style.display="none";}
? ? ? ? ? ? ? ? ? ??
//定義"顯示內(nèi)容"的函數(shù)
? ? function xs(){ ?var mychar=document.getElementById("txt");
? ? ? ? ? ? ? ? ? ? mychar.style.display="block";}
//定義"取消設(shè)置"的函數(shù)
? ? function qx(){ ?var mychar=document.getElementById("txt");
? ? ? ? ? ? ? ? ? ? var qd=confirm("是否要取消");
? ? ? ? ? ? ? ? ? ? if(qd=true){ mychar.className="#txt";}
? ? ? ? ? ? ? ? ? ? else{alert("不改變");}
? ? ? ? ? ? ? ? ? ? }
? </script>
2018-06-06
你還沒明白優(yōu)先級的問題,你雖然設(shè)定了class... ?但是style屬性比class高。。所以你調(diào)用class并不會對原有的style進(jìn)行覆蓋。。按思路你必須先清除style。。代碼可以這樣寫
function qx(){ ?
? ? ? ? ? ? ? ? ? ? var mychar=document.getElementById("txt");
? ? ? ? ? ? ? ? ? ? var qd=confirm("是否要取消");
? ? ? ? ? ? ? ? ? ? if(qd=true){?
? ? ? ? ? ? ? ? ? ? ? ? mychar.style= "";
????????????????????????mychar.className="txt"; ? 注意這里不要加#號。。#號是取ID的..
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? alert("不改變");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
2018-06-09
嗯的,我可以問下,你的頭像是那個人物的咩,耳朵看起來像起司貓,挺可愛的。。
2018-06-04
//定義"取消設(shè)置"的函數(shù)
? ? function qx(){ ?var mychar=document.getElementById("txt");
? ? ? ? ? ? ? ? ? ? var qd=confirm("是否要取消");
? ? ? ? ? ? ? ? ? ? if(qd=true){ mychar.removeAttribute("style");;}
? ? ? ? ? ? ? ? ? ? else{alert("不改變");}
? ? ? ? ? ? ? ? ? ? }
我還沒學(xué),網(wǎng)上搜的還原樣式的方法,測試了 可以用