函数传参

来源:互联网 发布:仿麦客网表单源码 编辑:程序博客网 时间:2024/06/05 10:16
1、字面量(常量):看到东西,自然知道是什么
    12,‘abc’
2、变量
    var a = ?
3、参数,变量不用加引号,除此之外的字符串都要叫引号

4、函数传参
    
    a:改变背景颜色
    函数传参:参数就是占位符

    什么时候传参--函数定不下来的东西


    b:改变div的任意样式
      操纵属性的第二种方式
      什么时候用:要修改的属性不固定
    字符和变量--区别与联系
      将属性名作为参数传递
5、style与className
    元素.style.属性=xxx是修改行间样式
    之后再修改className不会又效果

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title>    <style>        div{            width: 200px;            height: 200px;           background: red;        }    </style>    <script>        function setColor(color){            var odiv = document.getElementById("div");            odiv.style.background = color;        }        function toChange(name,value){            var odiv2 = document.getElementById("div2");            odiv2.style[name] = value;        }    </script></head><body><h2>改变相同样式</h2><input type="button" value="变蓝" onclick="setColor('blue')"/><input type="button" value="变红" onclick="setColor('red')"/><input type="button" value="变黄" onclick="setColor('yellow')"/><div id="div"></div><h2>改变不同样式</h2><input type="button" value="变宽" onclick="toChange('width','400px')"/><input type="button" value="变高" onclick="toChange('height','400px')"/><input type="button" value="变绿" onclick="toChange('background','green')"/><div id="div2"></div></body></html>


 
0 0