随笔分类 - JavaScript
原生javascript
摘要:<script> // 一句话 在构造函数里面写属性 在原型里面写方法 function Elem(d){ this.even=document.getElementById(d); } Elem.prototype.html=function(val){ var e = this.even; if
阅读全文
摘要:Document
阅读全文
摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> </head> <body> </body> <script type="text/javascript" > // 通过
阅读全文
摘要:var obj = new Object(); obj.name='Zachary'; obj.showname=function(){ alert(this.name) } obj.showname() // 任何对象都可以new function test(){...
阅读全文
摘要:var arr = new Array(12,13,14,15,16,17,18); var arr2 = new Array(12,13); arr.sun=function(){ //用原型加Array.prototype.sun=function() 下面的alert(arr2.sun())生
阅读全文
摘要:什么是对象 对象是一个整体,对外提供一些操作 就像黑盒子,不了解内部结构,但知道表面的各种操作 比如遥控器这个对象 什么是面向对象 在不了解原理的情况下会使用功能 使用对象时,只关注对象提供的功能,不关注内部实现和细节,比如jquery 面向对象是一种通用思想,并非编程中能用,任何事情都可以 为何使
阅读全文
摘要:<button id='btn'>attachEvent</button> window.onload=function(){ var Obtn = document.getElementById('btn'); Obtn.onclick=function(){ alert(1) } // 只兼容I
阅读全文
摘要:require是commonjs规范,是node的写法,webpack帮你做了语法转换,不单单是webpack可以做这事,gulp-browsers,requirejs一样可以 Node是commonjs规范,用require导入js模块,通过webpack等构建工具把require的js包注入到页面上,import是ES6/7的语法,如果浏览器支持,理论上不用构建工具就可以当作模块导入 n...
阅读全文
摘要:用Es6对象扩展运算符(…)与rest运算符说明 function test (...a) { for (let val = 0; val < a.length; val++) { console.log(val + ' ' + '常用的 for循环') // 0-7 便利出下标 } for (le
阅读全文
摘要:html打印结果子元素以及自身 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <style type="text/css"> .demo{width: 300px;height: 200px;border
阅读全文
摘要:css html javascript
阅读全文
摘要:随机取数方法 Math.random() 表示0到1之间随机取一个数 0<x<1 小数 Math.random()*5 表示0<x<5 parseInt(Math.random()*5) 0 1 2 3 4 中随机取一个数 公式:表示0到n 的随机取数(整数) parseInt(Math.random()*(n+1))
阅读全文
摘要:test function demo(){ return function test(a){ alert($(a).text()) } } demo()
阅读全文
摘要://原生js window.onresize = function() { console.log(document.body.clientWidth); } // jq方式 $(window).resize(function(){ console.log($(document.body).widt
阅读全文
摘要:console.time('计时器'); for (var i = 0; i < 1000; i++) { for (var j = 0; j < 1000; j++) {} } console.timeEnd('计时器');
阅读全文
摘要:var inp1=document.getElementById('inp1'); inp1.onfocus=function(){ if(inp1.value=="请输入..."){ inp1.value=""; inp1.style.color="white"; } } inp1.onblur=fu...
阅读全文