課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
JS入門篇的最后一個編程挑戰(zhàn)的第五個任務(wù),在經(jīng)過一系列的樣式改變后,寫一個函數(shù):點擊“取消設(shè)置”按鈕后恢復(fù)到原始值,請問怎么寫?
2015-11-24
源自:JavaScript入門篇 4-1
正在回答
removeAttribute('style');?
麥兜兜小敏 提問者
obj.removeAttribute("style");
<!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>javascript</title>
<style type="text/css">
#txt{
height:400px;
width:600px;
border:#333 solid 1px;
padding:5px;
}
p{
line-height:18px;
text-indent:2em;
</style>
</head>
<body>
<h2 id="con">Javascript</h2>
?<div id="txt">
? ?<h5>Javascript為網(wǎng)頁添加動態(tài)效果并實現(xiàn)與用戶交互功能。</h5>
? ?<p>1.Javascript入門篇,讓不懂JS的你,快速了解JS。</p>
? ?<p>2.Javascript進階篇,讓你掌握JS的基礎(chǔ)語法、函數(shù)、數(shù)組、事件、內(nèi)置對象、BOM瀏覽器、DOM操作。</p>
? ?<p>3.學(xué)完以上兩門基礎(chǔ)課后,在深入學(xué)習(xí)Javascript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? ?</div>
? ?<form>
? ?<input type="button" value="改變顏色" ?onclick="add1()"/>
? ?<input type="button" value="改變寬高" ?onclick="add2()"/>
? ?<input type="button" value="隱藏內(nèi)容" ?onclick="add3()"/>
? ?<input type="button" value="顯示內(nèi)容" ?onclick="add4()"/>
? ?<input type="button" value="取消設(shè)置" ?onclick="add5()"/>
? ?</form>
? ?<script type="text/javascript">
? ? function add1(){
var ad=document.getElementById("txt");
ad.style.color="red";
function add2(){
var ac=document.getElementById("txt");
ac.style.height="500px";
ac.style.width="700px";
function add3(){
var ab=document.getElementById("txt");
ab.style.display="none";
function add4(){
var aa=document.getElementById("txt");
aa.style.display="block";
function add5(){
var ag=document.getElementById("txt");
var ae=confirm("確定要取消設(shè)置")
if (ae==true){
ag.removeAttribute("style");
else{
ag.className="null";
</script>
</body>
</html>
慕粉2024224816
把不需要的remove掉就可以了
舉報
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
4 回答恢復(fù)原始值的代碼怎么寫
4 回答怎么恢復(fù)原始值?
4 回答怎么把在js中設(shè)置的樣式恢復(fù)原始值
6 回答恢復(fù)原始值
2 回答如何恢復(fù)原始值
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2015-11-24
removeAttribute('style');?
2017-07-02
obj.removeAttribute("style");
2016-08-24
<!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>javascript</title>
<style type="text/css">
#txt{
height:400px;
width:600px;
border:#333 solid 1px;
padding:5px;
}
p{
line-height:18px;
text-indent:2em;
}
</style>
</head>
<body>
<h2 id="con">Javascript</h2>
?<div id="txt">
? ?<h5>Javascript為網(wǎng)頁添加動態(tài)效果并實現(xiàn)與用戶交互功能。</h5>
? ?<p>1.Javascript入門篇,讓不懂JS的你,快速了解JS。</p>
? ?<p>2.Javascript進階篇,讓你掌握JS的基礎(chǔ)語法、函數(shù)、數(shù)組、事件、內(nèi)置對象、BOM瀏覽器、DOM操作。</p>
? ?<p>3.學(xué)完以上兩門基礎(chǔ)課后,在深入學(xué)習(xí)Javascript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? ?</div>
? ?<form>
? ?<input type="button" value="改變顏色" ?onclick="add1()"/>
? ?<input type="button" value="改變寬高" ?onclick="add2()"/>
? ?<input type="button" value="隱藏內(nèi)容" ?onclick="add3()"/>
? ?<input type="button" value="顯示內(nèi)容" ?onclick="add4()"/>
? ?<input type="button" value="取消設(shè)置" ?onclick="add5()"/>
? ?</form>
? ?<script type="text/javascript">
? ? function add1(){
var ad=document.getElementById("txt");
ad.style.color="red";
}
function add2(){
var ac=document.getElementById("txt");
ac.style.height="500px";
ac.style.width="700px";
}
function add3(){
var ab=document.getElementById("txt");
ab.style.display="none";
}
function add4(){
var aa=document.getElementById("txt");
aa.style.display="block";
}
function add5(){
var ag=document.getElementById("txt");
var ae=confirm("確定要取消設(shè)置")
if (ae==true){
ag.removeAttribute("style");
}
else{
ag.className="null";
}
}
</script>
</body>
</html>
2015-11-24
把不需要的remove掉就可以了