Created
November 4, 2014 15:54
-
-
Save briedis/c5aa0b4d4b1b5f840a7b to your computer and use it in GitHub Desktop.
examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\// veidojam vnk nodi, piemēram, div | |
mkE( { | |
tag:'div' | |
} ); | |
// node ar tekstu, to nevajag eskeipot | |
mkE( { | |
tag:'div', | |
text:'Hello world!' | |
} ); | |
//VAI | |
mkE( { | |
tag:'div', | |
els:[ | |
'Hello', | |
' ', | |
'World', | |
'!' | |
] | |
} ); | |
// node ar child nodēm, div, kurā ir span un tajā teksts | |
mkE( { | |
tag:'div', | |
els:[ | |
mkE( { | |
tag:'span', | |
text:'<><<><><><><>' // uzvars, neesceipojam | |
} ) | |
] | |
} ); | |
//* šo gadījumu vairāk lieto, tad ja vajadzīga reference uz node, piemēram: | |
var node; | |
mkE( { | |
tag:'div', | |
els:[ | |
node = mkE( { | |
tag:'span', | |
text:'<><<><><><><>' // uzvars, neesceipojam | |
} ) | |
] | |
} ); | |
// VAI | |
// zem els var būt arī mkE param struktūra, nav obligāti nodi | |
mkE( { | |
tag:'div', | |
els:[ | |
{ // mkE( | |
tag:'span', | |
text:'<><<><><><><>' // uzvars, neesceipojam | |
} | |
] | |
} ); | |
// elementu atribūti | |
mkE( { | |
tag:'div', | |
attr:{ | |
'data-test':123 | |
} | |
} ); | |
// propertiju setošana un eventu bindošana | |
mkE( { | |
tag:'a', | |
text:'link', | |
prop:{ | |
href:'/', | |
onclick:function(e){ | |
D.event(e); | |
// e - crossbrowser event object | |
} | |
} | |
} ); | |
/* | |
Shortcuts - propertiji, kurus var lietot pa taisno paramā bez prop:{} | |
*/ | |
var param = | |
{ | |
id:'test', | |
className:'abc', | |
style:{ | |
width:'10px', | |
borderTop:'1px solid #cc' | |
}, | |
innerHTML:'<b>123</b>' | |
}; | |
// tagu shortcuts | |
// img | |
param = | |
{ | |
src:'' | |
}; | |
// a | |
param = | |
{ | |
href:'javascript:' | |
}; | |
// select, option | |
param = | |
{ | |
value:'123' | |
}; | |
// input | |
param = | |
{ | |
value:'123', | |
type:'input', | |
name:'name', | |
checked:true | |
}; | |
// mkE rezultātiem ir šādas metodes: | |
mkE({}).append(parentNode); | |
mkE({}).remove(); | |
mkE({}).appendTo(jqueryText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment