el.addEventListener(eventName, handler , Booleans);
el.attachEvent('on' + eventName, function(){
handler.call(el);
});
el.removeEventListener(eventName, handler);
el.detachEvent('on' + eventName, handler);
if (document.createEvent) {
var event = document.createEvent('HTMLEvents');
event.initEvent('change', true, false);
el.dispatchEvent(event);
} else {
el.fireEvent('onchange');
}
var event = window.event||event;
var target = event.target || event.srcElement;
ul.addEventListener('click', function(event) {
if (event.target.tagName.toLowerCase() === 'li') {
console.log(event.target.innerHTML)
}
});
DOM加载完毕
function ready(fn) {
if (document.readyState != 'loading'){
document.addEventListener('DOMContentLoaded', fn);
} else {
document.attachEvent('onreadystatechange', function() {
if (document.readyState != 'loading'){
fn();
}
});
}
}