js函数传参

1、使用函数传参,就是在函数表示大致相同,但是有一个东西是定不下来的,把其作为参数放入其中。 

2、操作属性的两种方法:

var oDiv = document.getElementById('aa');

                oDiv.value='qwer';

                oDiv['value']='qwer';

                //第二种是里面输入一个字符串,其中的好处就是应用到函数传参进行改变属性的操作中用到

                或者以下

                oDiv.style.width='qwer';

                oDiv.style['width']='qwer';

        <style>

            #aa{width: 200px;height: 200px;background-color: palevioletred;}

        </style>

    <body>

        <div>

            <button onclick="change('width','500px');">变宽</button>

            <button onclick="change('height','500px');">变高</button>

            <button onclick="change('background-color','red');">变红</button>

        </div>

        <div id='aa'>           

        </div>

        <script>

            function change(name,value){

                var oDiv = document.getElementById('aa');

                oDiv.style[name]=value;             

            }

        </script>

    </body>

猜你喜欢

转载自www.cnblogs.com/tongguilin/p/12217657.html