javascript基础拾遗(十一)】的更多相关文章

1.DOM操作 1)查找 //根据id查找 document.getElementById() //根据html标签查找 documnet.getElementByTagName() //根据样式class查找 document.getElementsByClassName() 2)更新 DOM元素的innerHTML,innerText,textContent属性 var p = document.getElementById("p-id") p.innerHTML = 'ABC'…
1.jQuery的特点 jQuery是目前非常流行的javascript库,理念是"Write Less,Do More" 1)消除浏览器差异 2)简洁的操作DOM方法 3)轻松实现动画,修改CSS等各种操作 2.$符号 $是著名的jQuery符号,jQuery把所有功能都封装在一个全局函数jQuery中,$是全局函数jQuery的别名. window.jQuery; // jQuery(selector, context) window.$; // jQuery(selector,…
1.javascript的单线程特性 在javascript中,所有的代码都是单线程的 因此所有的网络操作,浏览器事件,都必须是异步执行的,异步执行的逻辑是回调. function callback() { console.log('hello') } console.log('begin') setTimeout(callback, 1000) console.log('end') 运行结果: begin end hello 2.Promise对象 像上列,和ajax等,承诺会在将来执行的对象…
1.支持ES6标准的浏览器 IE10+ Chrome Safari Firefox 移动端浏览器统一都支持 需要注意的是,不同浏览器对各个特性的支持也不一样 2.window对象 当前浏览器窗口对象 innerWidth,innerHeight可用于网页显示的净宽高 outerWidth,outerHeight整个浏览器的宽高 console.log(window.innerWidth) console.log(window.innerHeight) console.log(window.out…
1.对象的继承__proto__ var Language = { name: 'program', score: 8.0, popular: function () { return this.score/10*100 + '%'; } } var Python = { name: 'python', score: 9.0 } Python.__proto__ = Language console.log(Python.popular()) 运行结果: 90% __proto__属性将Pyth…
1.Date内置对象 获取系统时间 var now = new Date() console.log(now) console.log(now.getDate()) console.log(now.getDay()) console.log(now.getMilliseconds()) 2.构造Date对象 var now = new Date(2017, 12, 6) console.log(now) console.log(now.getDate()) console.log(now.get…
1.什么是箭头函数 ES6引入的一种新的函数,类似匿名函数,x=>xx 箭头左端为函数参数,右端为函数体 相当于 function (x){ retutn xx } 2.箭头函数的特点 更简洁 3.箭头函数和匿名函数的区别 箭头函数和匿名函数的区别在于this关键字的使用 在前面的总结中,知道对象的方法中定义的内部方法是无法使用this关键字的 箭头函数修复了这个缺陷,内部方法也可以使用this关键字,指向当前对象. 4.什么是生成器 javascript的生成器和python的生成器雷同,遇y…
1.对象定义 定义属性 var language = { name:'javascript', score:9.0 }; console.log(language.name) console.log(language.score) 定义方法 var language = { name:'javascript', score:9.0, percent: function () { var result = this.score/10*100 + '%'; return result; } }; c…
1.判断变量类型 var num = '123'; if(typeof num == 'number'){ alert('this is a number'); } else{ throw 'this is not a number'; } 2.arguments关键字 只在函数内部起作用,函数所有入参 function foo(x) { console.log('x is :' + x); for(var i=0;i<arguments.length;i++){ console.log('ar…
1.class关键字 ES6引入了新的class关键字编写对象 function Language(name){ this.name = name this.score = 8.0 } Language.prototype.popular = function () { return this.score/10*100 + '%' } class Language{ constructor(name){ this.name = name this.score = 8.0 } hello() {…