確認取消設(shè)置,恢復(fù)原始值,怎么設(shè)置?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<title>javascript</title>
<style type="text/css">
body{font-size:12px;}
#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>
? <!--當(dāng)點擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" onclick="yanse()" value="改變顏色" > ?
? ? <input type="button" onclick="kd()" value="改變寬高" >
? ? <input type="button" onclick="hidetext()" value="隱藏內(nèi)容" >
? ? <input type="button" onclick="showtext()" ?value="顯示內(nèi)容" >
? ? <input type="button" onclick="queren()" value="取消設(shè)置" >
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
function yanse() {
con.style.color="red";
con.style.backgroundColor="#CCC";
txt.style.color="blue";
txt.style.backgroundColor="#CCC";
}
//定義"改變寬高"的函數(shù)
function kd(){
? ? con.style.width="180px";
? ? con.style.height="50px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function hidetext() ?
? ? { ?
var mychar = document.getElementById("txt");
? ? mychar.style.display="none"; ? ?
} ?
//定義"顯示內(nèi)容"的函數(shù)
? ? function showtext() ?
{ ?
var mychar = document.getElementById("txt");
? ? mychar.style.display="block"; ? ??
}
//定義"取消設(shè)置"的函數(shù)
? function queren(){
? ? var mymessage=confirm("確認取消設(shè)置嗎?") ? ? ? ?;
? }
? </script>
</body>
</html>
2018-08-23
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<title>javascript</title>
<style type="text/css">
body{font-size:12px;}
#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>
? <!--當(dāng)點擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
??? <input type="button" value="改變顏色" onclick="yanse()"> ?
??? <input type="button" value="改變寬高" onclick="gaikuan()">
??? <input type="button" value="隱藏內(nèi)容" onclick="yincang()">
??? <input type="button" value="顯示內(nèi)容" onclick="xianshi()" >
??? <input type="button" value="取消設(shè)置" onclick="shezhi()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
var? chcolor=document.getElementById("txt");
function yanse(){
chcolor.style.color="blue";
chcolor.style.backgroundColor="#CCC";
}
//定義"改變寬高"的函數(shù)
function? gaikuan(){
chcolor.style.width="5";
chcolor.style.height="50";
}
//定義"隱藏內(nèi)容"的函數(shù)
function? yincang(){
chcolor.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function? xianshi(){
chcolor.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function shezhi(){
?var? chc=confirm("取消設(shè)置嗎?");
? if(chc==true){
????? chcolor.removeAttribute("style");
? }
?
}
? </script>
</body>
</html>
2017-09-11
//定義"顯示內(nèi)容"的函數(shù)
function dele() {
? ? if (confirm("是否取消設(shè)置?")){
? ? ? ? document.getElementById("txt").removeAttribute("style");
??
? ? }
? ? else{
? ? ? ? alert("已取消操作");
? ? }
? ??
? ??
}
2016-01-24
function quxiao(){
? ??
? ? var panduan=confirm("是否取消設(shè)置?");
? ? if(panduan==true){
? ? ? ? var dd=document.getElementById("txt");
? ? ? ? dd.removeAttribute('style');
? ? }
}
2015-12-06
?mychar.removeAttribute("style");方法有用
2015-06-10
樓上的騙子? 整個頁面刷新了? 原來寫的都重置了?? 還提交個屁啊
2015-05-22
parent.location.reload();
把這句加到你取消設(shè)置的代碼里面就可以了,具體什么用法和原理請自行百度。