為什么用取消設(shè)置用className 不管用? 大神幫看看 加粗部分!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js練習(xí)</title>
<style type="text/css">
body{ margin:0; padding:0; font-size:13px;}
.one{ width:500px; margin:0 auto; padding-left:20px; height:300px; border:1px solid #000; line-height:1.8em;}
h2{ text-align:center;}
form{text-align:center; line-height:50px;}
</style>
</head>
<body>
<h2>JavaScript 練習(xí)!</h2>
? ? <div id="text" class="one">
? ? <h5>Javascrip為網(wǎng)頁(yè)添加動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互的功能!</h5>
? ? ? ? <p>1. JavaScript入門(mén)篇,讓不懂JS的你,快速了解JS。</p>
? ? ? ? <p>2. JavaScript進(jìn)階篇,讓你掌握J(rèn)S的基礎(chǔ)語(yǔ)法、函數(shù)、數(shù)組、事件、內(nèi)置對(duì)象、BOM瀏覽器</p>
? ? ? ? <p>3. 學(xué)完以上兩門(mén)基礎(chǔ)課后,在深入學(xué)習(xí)JavaScript的變量作用域、事件、對(duì)象、運(yùn)動(dòng)、cookie、正則表達(dá)式、ajax等課程。</p> ??
? ? </div>
<form>
? ? <input name="button" type="button" onclick="changecolor()" value="改變顏色" />
? ? <input name="button" type="button" onclick="changewh()" value="改變寬高" />
? ? ? ? <input name="button" type="button" onclick="hiddencontent()" value="隱藏內(nèi)容" />
? ? ? ? <input name="button" type="button" onclick="showcontent()" value="顯示內(nèi)容" />
? ? ? ? <input name="button" type="button" onclick="cancle()" value="取消設(shè)置" />
? ? </form>
<script type="text/javascript">
var myartcle=document.getElementById("text");
function changecolor(){
myartcle.style.color="red";
}
function changewh(){
myartcle.style.width="600px";
myartcle.style.height="350px";
}
function hiddencontent(){
myartcle.style.display="none";
}
function showcontent(){
myartcle.style.display="block";
}
function cancle(){
var canc=confirm("確認(rèn)取消設(shè)置嗎?");
if(canc==ture){
myartcle.className="one";
}
}
</script>
</body>
</html>
2015-02-26
注意:if(canc==ture)中的這個(gè)ture寫(xiě)錯(cuò),應(yīng)該是true.同時(shí)要考慮css的優(yōu)先級(jí)順序:
下列是一份優(yōu)先級(jí)逐級(jí)增加的選擇器列表:
通用選擇器*
元素(類(lèi)型)選擇器
類(lèi)選擇器
屬性選擇器
偽類(lèi)
ID 選擇器
內(nèi)聯(lián)樣式
所以把className改成style方式試一試。