随笔分类 - js/jq
摘要:1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;ch
阅读全文
摘要:setInterval 1 var num = 0; 2 var max = 10; 3 var intervalId = null; 4 5 function incrementNumber() { 6 num++; 7 8 if (num == max) { 9 clearInterval(intervalId);10 console.log("Done");11 }12 }13 14 intervalId = setInterval(incrementNumber, 500);setTimeout 1 var num = 0; ...
阅读全文
摘要:1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;ch
阅读全文
摘要:1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;ch
阅读全文
摘要:1 var element = document.createElement("div"); 2 element.className = "message"; 3 4 var textNode = document.createTextNode("Hello world!"); 5 element.appendChild(textNode); 6 7 document.body.appendChild(element); 8 9 var newNode = element.firstChild.splitText(5);10 cons
阅读全文
摘要:1 var div = document.getElementById("myDiv");2 var comment = div.firstChild;3 console.log(comment.data);4 console.log(comment.nodeValue == comment.data);
阅读全文
摘要:1 var element = document.createElement("div"); 2 element.className = "message"; 3 4 var textNode = document.createTextNode("Hello world!"); 5 element.appendChild(textNode); 6 7 var anotherTextNode = document.createTextNode("Yippee!"); 8 element.appendChild(ano
阅读全文
摘要:1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;ch
阅读全文
摘要:1 var element = document.getElementById("myList");2 for (var i = 0, len = element.childNodes.length; i < len; i++) {3 if (element.childNodes[i].nodeType == 1) {4 console.log(element.childNodes[i].innerHTML);5 }6 } 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q
阅读全文
摘要:1 //Example 1 2 var returnedNode = someNode.appendChild(newNode); 3 console.log(returnedNode == newNode); 4 console.log(someNode.lastChild == newNode); 5 6 //Example 2 7 var returnedNode = someNode.appendChild(someNode.firstChild); 8 console.log(returnedNode == someNode.firstChild); //false 9 cons..
阅读全文
摘要:1 //寄生组合式继承 2 function object(o) { 3 function F() {} 4 F.prototype = o; 5 return new F(); 6 } 7 8 function inheritPrototype(subType, superType) { 9 var prototype = object(superType.prototype);10 prototype.constructor = subType;11 subType.prototype = prototype;12 }13 14 func...
阅读全文
摘要:1 //组合继承是Javascript最常用的继承模式 2 function SuperType(name) { 3 this.name = name; 4 this.colors = ["red", "blue", "green"]; 5 } 6 7 SuperType.prototype.sayName = function() { 8 console.log(this.name); 9 };10 11 function SubType(name, age) {12 //继承属性13 SuperType.call(this, na
阅读全文
摘要:1functionSuperType(){2this.property=true;3}45SuperType.prototype.getSuperValue=function(){6returnthis.property;7};89functionSubType(){10this.subproperty=false;11}1213//继承了SuperType14SubType.prototype=newSuperType();1516SubType.prototype.getSuperValue=function(){17returnthis.subproperty;18};1920varin
阅读全文
摘要:按对象取值:jQuery代码如下 1 (function ($) { 2 $.getJSON('ajax/test.json', function (data) { 3 var items = []; 4 5 $.each(data.comments, function (key, val) { 6 items.push('<li class="' + 'tag' + val.class + '">' + '<a href="#">' + val.co
阅读全文
摘要:1、简单跨域(子域):domian2、跨大域:postMessage
阅读全文
摘要:1functionPerson(){2}34Person.prototype.name="Nicholas";5Person.prototype.age=29;6Person.prototype.job="SoftwareEngineer";7Person.prototype.sayName=function(){8console.log(this.name);9};1011varperson1=newPerson();12person1.sayName();1314varperson2=newPerson();15person2.sayName();1
阅读全文
摘要:最近一个私活,客户要求有光源特效,本来想用Flash画的,可是看了jQuery动画(jQuery 1.4 Animation Techniques Beginner's Guide)以后觉得可以试试GitHub链接:https://github.com/qianzs/sun_scroll欢迎指点
阅读全文
摘要:1functionPerson(name,age,job){2this.name=name;3this.age=age;4this.job=job;5this.sayName=function(){6console.log(this.name);7};8}910varperson1=newPerson("Nicholas",29,"SoftwareEngineer");11varperson2=newPerson("Greg",27,"Doctor");1213person1.sayName();14person2
阅读全文
摘要:1functionselectFrom(lowerValue,upperValue){2varchoices=upperValue-lowerValue+1;3returnMath.floor(Math.random()*choices+lowerValue);4}56varnum=selectFrom(2,10);7console.log(num);89varcolors=["red","green","blue","yellow","black","purple",&qu
阅读全文
摘要:1varstringValue="yellow";2console.log(stringValue.localeCompare("brick"));3console.log(stringValue.localeCompare("yellow"));4console.log(stringValue.localeCompare("zoo"));chrome下brick显示为23,其他浏览器均为1
阅读全文

浙公网安备 33010602011771号