為什么只有顏色和取消可以》
? <form>
? <!--當點擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="changeColor()"> ?
? ? <input type="button" value="改變寬高" onclick="changeS()">
? ? <input type="button" value="隱藏內(nèi)容"
? ? onclick="objHide()">
? ? <input type="button" value="顯示內(nèi)容"
? ? onclick="objShow()">
? ? <input type="button" value="取消設(shè)置"
? ? onclick="offSet()">
? </form>
? <script type="text/javascript">
? ?var txt=document.getElementById("txt");{
function changeColor(){
//定義"改變顏色"的函數(shù)
txt.style.color="red";
txt.style.backgroundColor="green";}
//定義"改變寬高"的函數(shù)
function changeS(){
txt.style.height="400px";
txt.style.width="600px";}
//定義"隱藏內(nèi)容"的函數(shù)
function objHide()
{
?txt.style.display="block";
?txt.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
? function offSet(){
? ? txt.removeAttribute('style')
}
//定義"取消設(shè)置"的函數(shù)
}
2016-01-08
1、改變寬高函數(shù):窗口本來大小就是400px高 600px寬,你函數(shù)中沒有變化,自然沒有反應(yīng)。
2、顯示函數(shù):沒有定義,自然沒有顯示。顯示函數(shù)中寫了2條display
2016-01-07
objShow()哪去了,沒定義這個函數(shù)呀。
changeS()里設(shè)置的寬高和原本的CSS的寬高一樣,當然看不出變化。
objHide()里又要隱藏又有顯示,是要干嘛。
取節(jié)點的語句后面為何還有花括號,沒必要呀。
修改后的JS你看看,有什么不懂再提出來