龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

解决JS在firefox和IE下差异问题(1)(2)

时间:2013-03-06 14:58来源:未知 作者:admin 点击:
分享到:
8.window.event问题 说明:window.event只能在IE下运行,而不能在Firefox下运行,这是因为Firefox的event只能在事件发生的现场使用. 解决方法: IE: inputname inputname =Button

8.window.event问题

说明:window.event只能在IE下运行,而不能在Firefox下运行,这是因为Firefox的event只能在事件发生的现场使用.
解决方法:

IE: 

  1. <inputnameinputname="Button8_1"type="button"
  2. value="IE"onclick="javascript:gotoSubmit8_1()"/> 
  3. ...  
  4. <scriptlanguagescriptlanguage="javascript"> 
  5. functiongotoSubmit8_1(){  
  6. ...  
  7. alert(window.event);//usewindow.event  
  8. ...  
  9. }  
  10. </script> 
  11. IE&Firefox:  
  12. <inputnameinputname="Button8_2"type="button"
  13. value="IE"onclick="javascript:gotoSubmit8_2(event)"/> 
  14. ...  
  15. <scriptlanguagescriptlanguage="javascript"> 
  16. functiongotoSubmit8_2(evt){  
  17. ...  
  18. evtevt=evt?evt:(window.event?window.event:null);  
  19. alert(evt);//useevt  
  20. ...  
  21. }  
  22. </script> 

9.event.x与event.y问题

说明:IE下,even对象有x,y属性,但是没有pageX,pageY属性;Firefox下,even对象有pageX,pageY属性,但是没有x,y属性.
解决方法:使用mX(mX=event.x?event.x:event.pageX;)来代替IE下的event.x或者Firefox下的event.pageX.

10.event.srcElement问题

说明:IE下,even对象有srcElement属性,但是没有target属性;Firefox下,even对象有target属性,但是没有srcElement属性.
解决方法:使用obj(obj=event.srcElement?event.srcElement:event.target;)来代替IE下的event.srcElement或者Firefox下的event.target.

11.window.location.href问题

说明:IE或者Firefox2.0.x下,可以使用window.location或window.location.href;Firefox1.5.x下,只能使用window.location.
解决方法:使用window.location来代替window.location.href.

12.模态和非模态窗口问题

说明:IE下,可以通过showModalDialog和showModelessDialog打开模态和非模态窗口;Firefox下则不能.
解决方法:直接使用window.open(pageURL,name,parameters)方式打开新窗口。如果需要将子窗口中的参数传递回父窗口,可以在子窗口中使用window.opener来访问父窗口.例如:varparWin=window.opener;parWin.document.getElementById(Aqing).value=Aqing;

精彩图集

赞助商链接