「javascript高級プログラム設計」第一版ノート
13545 ワード
, undefined
undefined , .null (null == undefined)
boolean ,undefined、null、 、0 false, true;
, Boolean , 。
== === == , ===
with ,
java js switch : js switch case
js ,
js : undefined、null、Number、String、Boolean
js : String、Number、Boolean、Object ( , )
encodeURI encodeURIComponent : , : --> %20
escape encodeURI : escape ascii ,
cell , floor ,round
location.reload(true); , false
obj.attributes.getNamedItem('id').nodeValue
document.all ie document.getElementsByTagName('*') other browser return
document.getElementsByName ie6 input img
document.getElementById('abc') ie6 abc id name
dom class className , class class ,
NodeIterator TreeWalker dom
dom (DOM)、 (IE),dom documentElement , 。 ie documentElement
addEventListener、removeEventListener ie6-ie8 attachEvent、detachEvent
:13 :32 :8
var target=event.srcElement || event.target; //
var char=target.keyCode || target.charCode; //
event.returnValue=false ie event.preventDefault(); dom
event.cancelBubble=true ie event.stopPrapagation() dom cancelBubble stopPropagation
keyDown > keyPress > keyUp
keyDown > keyUp
, keyDown、keyPress 。 keyDown
obj.currentStyle.color ie getComputedStyle(obj,null).color dom ,null :'hover'
innerHTML、outerHTML、innerText、outerText firefox(16.0.0) *Text, *html,chrome
EvalError、ReferenceError、RangeError、synatexError、TypeError、URIError js
document.domain='qq.com' , 。 url , baidu.com
1160 tcp-ip , js 1160
/* '+' */
function StringBuffer(){
this._strings=new Array();
}
StringBuffer.prototype.append=function(str){
this._strings.push(str);
}
StringBuffer.prototype.toString=function(){
return this._strings.join('');
}
var d=new Date();
var sb=new StringBuffer();
for(i=0;i<100000;i++){
sb.append(i);
}
sb.toString();
var d2=new Date();
console.log(d2-d);
/* / */
function o(a,b,c){
this.a=a;
this.b=b;
this.c=c;
}
o.prototype.m=function(){
console.log(this.a);
}
var t1=new o(1,2,3);
var t2=new o(4,5,6);
t1.m();
t2.m();
/* call apply */
function classA(a,b){
console.log(a+','+b);
}
function classB(a,b){
classA.call(this,a,b); //
classA.apply(this,arguments); //
this.a=a;
this.b=function(){
console.log(a);
}
}
var t1=new classB('1','2');
t1.b();
var t2=new classA('3','4');
/* */
var arr=[1,2,3,4,5,6];
var oFragment=document.createDocumentFragment();
for(i in arr){
var oDiv=document.createElement('span');
var oText=document.createTextNode(i);
oDiv.appendChild(oText);
oFragment.appendChild(oDiv);
}
document.body.appendChild(oFragment);
/* dom */
obj.firstChild
obj.lastChild
obj.childNodes
obj.nodeName
obj.nodeValue
obj.nodeType
obj.ownerDocument
obj.previousSibling
obj.nextSibling
obj.hasChildNodes
obj.attributes
obj.appendChild
obj.removeChild
obj.replaceChild(newNode,oldNode)
obj.insertBefore(newNode,refNode)
/* dom */
document.createElement
document.createTextNode; (text)
document.appendChild;
document.createDocumentFragment , fragment , ,
/* addEventListener*/
function show(){alert('clicked');}
var arr=[1,2,3,4,5,6];
var oFragment=document.createDocumentFragment();
for(i in arr){
var oDiv=document.createElement('div');
var oText=document.createTextNode(i);
oDiv.addEventListener('click',show,false); //false: true:
oDiv.appendChild(oText);
oFragment.appendChild(oDiv);
}
document.body.appendChild(oFragment);
/* */
var EventUtil=new Object;
EventUtil.addEventHandler=function(oTarget,sEventType,fnHandler){
if(oTarget.addEventListener)
oTarget.addEventListener(sEventType,fnHandler,false); //false
else if(oTarget.attachEvent)
oTarget.attachEvent('on'+sEventType,fnHandler);
else
oTarget['on'+sEventType]=fnHandler;
}
EventUtil.removeEventHandler=function(oTarget,sEventType,fnHandler){
if(oTarget.removeEventListener)
oTarget.removeEventListener(sEventType,fnHandler,false)
else if(oTarget.detachEvent)
oTarget.detachEvent('on'+sEventType,fnHandler);
else
oTarget['on'+sEventType]=null;
}
/* css */
var oCSSRules=document.styleSheets[0].cssRules || document.styleSheets[0].rules;
var css='';
for(i=0;i//
css+=oCSSRules[i].cssText;
//oCSSRules[i].style.color; //
console.log(css);
/*js 、 、 */
function Person(age,face){
var age=age; //
this.face=face; //
Person.gender='man'; //
}
var p1=new Person(20,' ');
var p2=new Person(22,' ');
Person.gender; // Person (Person() || new Person())
p1.gener;
p1.age;
p1.face;
転載先:https://www.cnblogs.com/BigIdiot/archive/2012/11/21/2781157.html