Home > Web Front-end > JS Tutorial > body text

IE browser compatible with Firefox JS script code_javascript skills

WBOY
Release: 2016-05-16 18:59:30
Original
899 people have browsed it

1. window.event compatible script
2. Shield Form submission event
3. Get event source
4. Add event compatible writing method
5. Firefox registration innerText writing method
6. Length
7. Child controls under the parent control
8. if(document.all) return window.event;
func=getEvent.caller;
while(func!=null){
var arg0=func.arguments[0];
if(arg0 ){
if((arg0.constructor==Event   arg0.constructor ==MouseEvent)
  (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){
return arg0 ;
}
}
func=func.caller;
}
return null;
}
Firefox needs to use getEvent() to get it every time before using the event. Otherwise it is empty
2. Shield the Form submission event
event.returnValue=false;// for IE
evt.preventDefault();//for firefox
3. Get the event source
var source=event.srcElement //IE
var source=event.target //firefox
4. Add event compatible writing
function addEvent(oElement,sEvent,func){
if (oElement.attachEvent ){
oElement.attachEvent(sEvent,func);
}
else{
sEvent=sEvent.substring(2,sEvent.length);
oElement.addEventListener(sEvent,func, false);
}
}
Usage: addEvent(window,"onload",Start);
5.Firefox registration innerText writing method
//Register firefox innerText
HTMLElement.prototype .__defineGetter__("innerText",
function(){
var anyString = "";
var childS = this.childNodes;
for(var i=0; i if(childS[i] .nodeType==1)
anyString = childS[i].tagName=="BR" ? 'n' : childS[i].innerText;
else if(childS[i].nodeType==3)
anyString = childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__("innerText",
function(sText ; is "children", FireFox is "childNodes"
8. , otherwise a 411 error will occur

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template