這樣會不會簡潔點(diǎn)
function fn(str){
var txt = document.getElementById("txt");
if(str=="1"){
txt.style.color = "red";
}else if(str=="2"){
txt.style.width="900px";
txt.style.height="300px";
}else if(str=="3"){
txt.style.display="none";
}else if(str=="4"){
txt.style.display="block";
}else if(str=="5"){
var sel = confirm("是否取消設(shè)置?")
if(sel==true){
var txt=document.getElementById("txt");
txt.removeAttribute("style");
}
}
}
2020-04-28
我是這樣弄的
<script type="text/javascript">
//定義"改變顏色"的函數(shù)
function btn1(){
??? var div=document.getElementById("txt");
??? div.style.color="yellow";
??? div.style.backgroundColor="gray";
}
//定義"改變寬高"的函數(shù)
function btn2(){
??? var div2=document.getElementById("txt");
??? div2.style.width="500px";
??? div2.style.height="300px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function btn3(){
??? var div3=document.getElementById("txt");
??? div3.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function btn4(){
??? var div4=document.getElementById("txt");
??? div4.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function btn5(){
??? var div5=document.getElementById("txt");
??? var con=confirm("是否取消設(shè)置?");
??? if(con==true){
??????? div5.removeAttribute("style");
??? }
}
? </script>