新聞中心
本文向大家描述一下Firefox瀏覽器兼容JS腳本問(wèn)題,最近做了一個(gè)項(xiàng)目,遇到了FireFox和IE腳本不兼容的問(wèn)題,為此從網(wǎng)上搜集了部分兼容的腳本,這里和大家分享一下,希望對(duì)你的學(xué)習(xí)有所幫助。

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括晉源網(wǎng)站建設(shè)、晉源網(wǎng)站制作、晉源網(wǎng)頁(yè)制作以及晉源網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專(zhuān)注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,晉源網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到晉源省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
Firefox瀏覽器兼容JS腳本供參考
1.window.event兼容腳本
- functiongetEvent(){//獲取瀏覽器事件,同時(shí)兼容ie和ff的寫(xiě)法
- if(document.all)returnwindow.event;
- func=getEvent.caller;
- while(func!=null){
- vararg0=func.arguments[0];
- if(arg0){
- if((arg0.constructor==Event arg0.constructor==MouseEvent)
- (typeof(arg0)=="object"&&arg0.preventDefault&&arg0.stopPropagation)){
- returnarg0;
- }
- }
- funcfunc=func.caller;
- }
- returnnull;
- }
每次用事件之前Firefox都需要用getEvent()獲取一下,否則就是空
2.屏蔽Form提交事件
- event.returnValue=false;//forIE
- evt.preventDefault();//forfirefox
3.獲取事件源
- varsource=event.srcElement//IE
- varsource=event.target//firefox
#p#4.添加事件兼容寫(xiě)法
- functionaddEvent(oElement,sEvent,func){
- if(oElement.attachEvent){
- oElement.attachEvent(sEvent,func);
- }
- else{
- sEventsEvent=sEvent.substring(2,sEvent.length);
- oElement.addEventListener(sEvent,func,false);
- }
- }
用法:addEvent(window,"onload",Start);
5.Firefox注冊(cè)innerText寫(xiě)法
- //注冊(cè)firefoxinnerText
- HTMLElement.prototype.__defineGetter__("innerText",
- function(){
- varanyString="";
- varchildS=this.childNodes;
- for(vari=0;iif(childS[i].nodeType==1)
- anyString+=childS[i].tagName=="BR"?'\n':childS[i].innerText;
- elseif(childS[i].nodeType==3)
- anyString+=childS[i].nodeValue;
- }
- returnanyString;
- }
- );
- HTMLElement.prototype.__defineSetter__("innerText",
- function(sText){
- this.textContent=sText;
- }
- );
6.長(zhǎng)度:FireFox長(zhǎng)度必須加“px”,IE無(wú)所謂
7.父控件下的子控件:IE是“children”,F(xiàn)ireFox是“childNodes”
8.XmlHttp
在IE中,XmlHttp.send(content)方法的content可以為空,而firefox則不能為空,應(yīng)該用send(""),否則會(huì)出現(xiàn)411錯(cuò)誤
分享標(biāo)題:學(xué)習(xí)筆記Firefox瀏覽器兼容JS腳本
轉(zhuǎn)載來(lái)源:http://www.dlmjj.cn/article/cosdgep.html


咨詢
建站咨詢
