42 lines
909 B
JavaScript
42 lines
909 B
JavaScript
|
|
function my$(id){
|
|
return document.getElementById(id)
|
|
}
|
|
|
|
//获取文本内容兼容代码
|
|
function getInnerText(element){
|
|
if(element.textContent){
|
|
return element.textContent
|
|
}else if(element.getInnerText){
|
|
return element.innerText
|
|
}
|
|
}
|
|
|
|
//获取文本内容兼容代码
|
|
function getInnerText(element,value){
|
|
if(element.textContent){
|
|
element.textContent = value
|
|
}else if(element.getInnerText){
|
|
element.innerText = value
|
|
}
|
|
}
|
|
//为任意元素绑定事件的兼容
|
|
function addEventListener(ele,type,fn){
|
|
if(ele.addEventListener){
|
|
ele.addEventListener(type,fn,false)
|
|
}else if(ele.attachEvent){
|
|
ele.attachEvent('on'+type,fn)
|
|
}else{
|
|
els['on'+type] = fn
|
|
}
|
|
}
|
|
|
|
//解绑事件的兼容
|
|
function removeEventListener(ele,type,fn){
|
|
if(ele.removeEventListener){
|
|
ele.removeEventListener(type,fn,false)
|
|
}else if(ele.detachEvent){
|
|
ele.detachEvent('on'+type,fn)
|
|
}else{
|
|
ele['on'+type] = null
|
|
} |