• 智能社js学习笔记


    style.height书写方式与style[height]  书写等价 即.可与[]互换

    可以用.的地方也可以用[],但是[]更好的地方在于可以用在函数传参

    <script type="text/javascript">
    function to(name,num){
        var to=document.getElementById('div1');
        to.style[name]=num;
         }
    </script>
    
    </head>
    <body>
        <button   onclick="to('backgroundColor','red')">变红</button>
        <button onclick="to('height','400px')">变高</button>
    <div id="div1">
    </div>
    </body>

    style加样式是在行间添加,取样式也是在行间取,如果样式写在外部文件,则style无效;

    非行间利用currentStyle,但是只支持IE;只能读取样式,不能写样式

    getComputedStyle,只能读取样式,不能写样式        支持火狐谷歌  getComputedStyle有两个参数getComputedStyle(“元素”,“伪类”l)第一个元素是,第二个参数是伪类,Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) 之前,第二个参数“伪类”是必需的(如果不是伪类,设置为null),不过现在嘛,不是必需参数了,没有用相当于垃圾,传什么都可以,返回的是一个CSS样式声明对象([object CSSStyleDeclaration])

    样式优先级:*通配符<标签<class<id<行间style

    用了style之后再修改className就不起作用了,因为style的优先级大于className,所以全篇如果用style就一直就style,若用className就一直用className

    arguments(可变参、不定参)参数的个数可变,参数数组

    1、可用于检测参数个数

    function sum(){
        alert(arguments.lenth);
    }
    sum(2,1,3);//结果3
    sum()//结果0
    sum("string",3)//结果2
    

     2、可用于模拟函数重载

    function doAdd() {
      if(arguments.length == 1) {
        alert(arguments[0] + 5);
      } else if(arguments.length == 2) {
        alert(arguments[0] + arguments[1]);
      }
    }
    
    doAdd(10);    //输出 "15"
    doAdd(40, 20);    //输出 "60"

     数组操作:

    push(x):尾部添加   eg:var arr[]=[1,2,3];  arr.push(4);   alert(arr);//弹出结果为1,2,3,4

    pop():尾部删除   eg:var arr[]=[1,2,3];  arr.pop();   alert(arr);//弹出结果为1,2

    shift():头部添加

    unshift():头部删除

    splice(起点,长度):删除从起点开始长度为设定的数组元素

    splice(起点,长度,元素....):插入从起点开始删除长度个元素再插入元素

     定时器:

    setInterval(函数,时间):无限执行

    setTimeout(函数,时间):执行一次

  • 相关阅读:
    Linux学习笔记 -- stdin/stdout 重定向
    Linux学习笔记
    使用 maven 构建 SpringMVC
    Linux学习笔记
    (转)Tomcat 启动后 “闪退”
    解决: Project facet Java version 1.8 is not supported
    由 MySQL server 和 mysql-connector 版本的不匹配引发的一场惊魂
    Adobe Acrobat 不能打开在线pdf。Adobe Acrobat 应用程序正在被终止,因为内存错误
    收缩数据库日志文件
    android基站定位程序获取地理位置
  • 原文地址:https://www.cnblogs.com/wyy725872/p/4497209.html
Copyright © 2020-2023  润新知