代碼差不多,為什么不行呢?
<form>
? <input type="button" value="改變顏色" onClick="dcolor()">
? <input type="button" value="改變寬高" onClick="dwh()">
? <input type="button" value="隱藏內(nèi)容" onClick="dh()">
? <input type="button" value="顯示內(nèi)容" onClick="ds()">
? <input type="button" value="恢復" onClick="dclear()">??
? </form>
? <script type="text/javascript">
function dcolor()
{? ?var mychar = document.getElementById("txt");
? ? mychar.style.color="red";
? ? mychar.style.backgroundColor="#ccc";
}
function dwh(){
? ?var mychar=document.getElementById("txt");
? ? mychar.style.width="300px";
? ? mychar.style.height="600px";
}
function dh(){
? ? var mychar=document.getElementById("txt");
? ? mychar.style.display="none"; ?
}
function ds(){
? ? var mychar=document.getElementById("txt");
? ? mychar.style.display="block";? ?
}
function dclear(){?
? ? var mm=confirm("是否恢復原始設置:");
? ? if(mm==true)
? ? { mydd.className="txt"; }
}
? </script>
</body>
</html>
2016-05-18
function dclear(){?
? ? var mm=confirm("是否恢復原始設置:");
? ? if(mm==true)
? ? { mydd.className="txt"; }
}有問題。
function dclear(){
? ? if(confirm("確定取消設置嗎?")){
? ? var mychar=document.getElementById("txt");
? ? mychar.style.color="#000";
? ? mychar.style.background="#fff";
? ? mychar.style.width="600px";
? ? mychar.style.height="400px";
? ? mychar.style.display="block";
? ? }
} ?用這個吧。至于原因,二樓說的應該是對的。
2016-05-18
換個瀏覽器試試,不同瀏覽器規(guī)則不同。
2016-05-18
<meta http-equiv="txttent-Type" txttent="text/html; charset=gb2312" />txttent是content,恢復原始數(shù)據(jù)的時候,用className沒有用,因為js設置的style比class的優(yōu)先,所以要去掉用mychar.removeAttribute("style");
2016-05-18
{}后未加分號