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
cdm→ componentDidMount: fn() { ... } | |
cdup→ componentDidUpdate: fn(pp, ps) { ... } | |
cs→ var cx = React.addons.classSet; | |
cwm→ componentWillMount: fn() { ... } | |
cwr→ componentWillReceiveProps: fn(np) { ... } |
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
document.addEventListener('eventName', function(){ | |
var win = window.open(); | |
win.document.write('<h1>test open window</h1>'); // write content in new opened window | |
win.document.close(); | |
}, false); |
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
function wheelHandle(e) { | |
if(e.wheelDelta) {// IE, KHTML, Opera | |
alert(e.wheelDelta > 0 ? '向上滚' : '向下滚'); | |
} else { // Gecko | |
alert(e.detail < 0 ? '向上滚' : '向下滚'); | |
} | |
} |
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
mouseenter事件在鼠标进入某个元素,或第一次进入这个元素的某个子元素时触发。一旦触发后,在mouseleave之前,鼠标在这个元素的子元素上触发mouseenter事件都不会触发这个元素的mouseenter事件。即:一旦进入,在子元素间的mouseenter不算是在本元素上的mouseenter。 | |
而mouseover事件是必然冒泡的,一旦子元素mouseover了,本元素必然mouseover(除非子元素上禁止冒泡了)。 |
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
function parseURL(url) { | |
var a = document.createElement('a'); | |
a.href = url; | |
return { | |
source: url, | |
protocol: a.protocol.replace(':',''), | |
host: a.hostname, | |
port: a.port, | |
query: a.search, | |
params: (function(){ |
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
// copied from quora answer by David-Calhoun | |
// https://www.quora.com/David-Calhoun | |
if (document.addEventListener) { // standard | |
document.addEventListener('click', function onclick(e) { | |
var r; | |
if (document.caretRangeFromPoint) { // standard (WebKit) | |
r = document.caretRangeFromPoint(e.pageX, e.pageY); | |
} else if (e.rangeParent) { // Mozilla | |
r = document.createRange(); |
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
function createIframe(fname){ | |
if(!fname || typeof fname !== 'string'){ | |
return document.createElement('iframe'); | |
} | |
var ifr = null; | |
try{ | |
ifr = document.createElement('<iframe name=' + fname + '></iframe>'); | |
}catch(e){ | |
ifr = document.createElement('iframe'); | |
ifr.name = fname; |
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
keycode 8 = BackSpace BackSpace | |
keycode 9 = Tab Tab | |
keycode 12 = Clear | |
keycode 13 = Enter | |
keycode 16 = Shift_L | |
keycode 17 = Control_L | |
keycode 18 = Alt_L | |
keycode 19 = Pause | |
keycode 20 = Caps_Lock | |
keycode 27 = Escape Escape |
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
//计算字符串长度,中文按2 | |
function getStringLen(str) { | |
var cArr = str.match(/[^\x00-\xff]/ig); | |
return str.length + (cArr == null ? 0 : cArr.length); | |
} |
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
var isIE = (function(){ | |
var v = 3, | |
div = document.createElement('div'), | |
all = div.getElementsByTagName('i'); | |
//通过IE检测HTML条件注释方式 | |
//循环判断IE浏览器当前支持版本 | |
while ( | |
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', | |
all[0] | |
); |
NewerOlder