請問:1、clsaaName="classname"的樣式怎么清除(點擊取消重置會恢復到改變樣式的狀態) 2、改變行高后我的按鈕為什么會跑上去 3、先改變行高再變樣式時背景和邊框變得很小
<!doctype html>
<html>
?<head>
? <meta charset="UTF-8">
? <meta name="Generator" content="EditPlus?">
? <meta name="Author" content="">
? <meta name="Keywords" content="">
? <meta name="Description" content="">
? <title>Document</title>
? <style>
? *{margin:0;padding:0;}
? body{font-size:22px;}
.biana{
height:200px;
width:400px;
line-height:20px;
border:red solid 2px;
padding:5px;
color:green;
background:gray;}
.hanggao{
line-height:15px;
text-indent:2em;}
? </style>
?</head>
?<body>
?<div id=all>
?<h5 id="h5">JavaScript課程</h5>
?<div id="p">
? <h5>JavaScript為網頁添加動態效果并實現與用戶交互的功能。</h5>
? <p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>
? <p>2. JavaScript進階篇,讓你掌握JS的基礎語法、函數、數組、事件、內置對象、BOM瀏覽器、DOM操作。</p>
? <p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
?</div>
?</div>
?<form>
? <input type="button" value="改變樣式" name="changecolor" onclick="bian()" />
? <input type="button" value="改變行高" name="changecolor" onclick="hanggao()" />
? <input type="button" value="隱藏內容" name="changecolor" onclick="hid()" />
? <input type="button" value="顯現內容" name="changecolor" onclick="xian()" />
? <input type="button" value="取消重置" name="changecolor" onclick="cancel()" />
? </form>
? ? <script>
var a=document.getElementById("p");
//改變背景樣式函數
function bian()
{
a.className="biana"
}
//改變行高函數
function hanggao()
{
a.style.width="200px";
a.style.height="20px";
}
//隱藏內容函數?
function hid()
{
a.style.display="none";
}
//顯示內容函數
function xian()
{
a.style.display="block";
}
//取消設置函數
function cancel()
{
var sure=confirm("你確定要重置嗎?");
if(sure==true)
{
a.removeAttribute("style");
}
}
? </script>
?</body>
</html>
2019-07-22
//取消設置函數
function cancel() {
var sure = confirm("你確定要重置嗎?");
if (sure == true) {
a.removeAttribute("style");
a.className = ""
}
}
這個記得重置后把a的className 設置為空。。。
改變行高時候內容是由高度撐起來的,所以設置為auto
2019-07-22
此事要從袁隆平說起