1,通过JS创建对象,属性,方法
var person = new Object(); //创建对象; person.name = "lisi"; //创建属性; person.age = 21; person.family = ["lida", "lier", "wangwu"]; person.say = function () { //创建方法; return this.name; }; console.log (person.say()); //返回 lisi; console.log (person.family[2]); // 返回wangwu;
点击 "运行实例" 按钮查看在线实例
2.Jquery选择器的使用和$each循环
<!DOCTYPE html> <html> <head> <title>jquery</title> <script src="../jquery-3.4.1.min.js"></script> </head> <body> <div class="main"> <div class="header"> <div class="nav"> <a id="home">首页</a> <a>视频教程</a> </div> </div> <div class="imgs"> <img src=""> </div> </div> </body> <script> var num = $('#home').html(); console.log(num); var res = $('.main>div'); console.log(res.length); $.each(res, function (i, v) { console.log(v); }); </script> </html>
点击 "运行实例" 按钮查看在线实例