關(guān)于ID問題
//定義"改變顏色"的函數(shù)
function gbys(){
txt.style.color="red";
txt.style.backgroundColor="pink";
}
//定義"改變寬高"的函數(shù)
function gbkg(){
txt.style.width="400px";
txt.style.height="300px"
}
//定義"隱藏內(nèi)容"的函數(shù)
function ycnr(){
txt.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function xsnr(){
txt.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function qxsz(){
if (confirm("是否取消設(shè)置?")){
txt.style.color="#000";
txt.style.backgroundColor="#fff";
txt.style.weidth="600px";
txt.style.height="400px";
txt.style.display="block";
}
}
例隱藏內(nèi)容:
根本不需要定義 var yc = document.getElementById("txt");
????????????????????????yc.style.display="none";
直接用????????????? txt.style.display="none"; ?也可以啊,那為什么要定義
????????????????????????var yc = document.getElementById("txt");
2015-12-17
變量雖然也可以不聲明,直接使用,但不規(guī)范,所有需要先聲明,后使用。