关于ID问题

来源:4-1 编程挑战

愛39

2015-07-24 20:35

//定义"改变颜色"的函数

function gbys(){

txt.style.color="red";

txt.style.backgroundColor="pink";

}

//定义"改变宽高"的函数

function gbkg(){

txt.style.width="400px";

txt.style.height="300px"

}

//定义"隐藏内容"的函数

function ycnr(){

txt.style.display="none";

}

//定义"显示内容"的函数

function xsnr(){

txt.style.display="block";

}

//定义"取消设置"的函数

function qxsz(){

if (confirm("是否取消设置?")){

txt.style.color="#000";

txt.style.backgroundColor="#fff";

txt.style.weidth="600px";

txt.style.height="400px";

txt.style.display="block";

}

}

例隐藏内容:

根本不需要定义 var yc = document.getElementById("txt");

                        yc.style.display="none";

直接用              txt.style.display="none";  也可以啊,那为什么要定义

                        var yc = document.getElementById("txt");

写回答 关注

1回答

  • 艳子00
    2015-12-17 14:38:01

    变量虽然也可以不声明,直接使用,但不规范,所有需要先声明,后使用。

JavaScript入门篇

JavaScript做为一名Web工程师的必备技术,本教程让您快速入门

741122 学习 · 9865 问题

查看课程

相似问题