Blogger Information
Blog 9
fans 0
comment 1
visits 5983
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
10月23日JS创建对象属性、方法及jquery
张大千的博客
Original
652 people have browsed it

1、练习JS创建对象、属性、方法。

    <script>

        //创建对象,属性和方法

        var obj = new Object();

        obj.rand = function() {

            console.log(Math.random());//打印随机数

        }

        obj.rand();  //打印方法

        obj.name = 'php';//创建属性

        console.log(obj.name);//打印属性

        obj.sum = function(a, b) {

            return a + b;

        }

        alert(obj.sum(50, 60));

//第二种创建对象属性和方法。

        var obj2 = {

            name: 'php',

            rand: function() {

            },

            sum: function() {

            }

        };

    </script>

2、jquery的id、class选择器选择元素,$.each遍历数组

    <div id='div' style="width: 300px; height: 300px; background-color: chartreuse;"></div>

    <script>

        function aa() {

            //第一种写法{}

            // $('#div').css({

            //     'width': '400px',

            //     'height': '400px',

            //     'background': '#ff0000'

            // });

            //第二种写法

            $('#div').css('width', '400px');

        }

    </script>

    <button onclick="aa()">点击一下div变大小</button>

3、$.each遍历数组

    <script>

        var aa = ['张三', '李四', '王五', '赵六'];

        $.each(aa, function(i, n) {

            console.log(i + ':' + n);

        })

    </script>

Correction status:qualified

Teacher's comments:下次把代码放在代码框中提交, 还要写作业总结, 看一下群公告中的作业要求
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post