3>使用childNode()代替之前的children4>手型鼠标指针请用cursor:pointer,不用cursor:hand5>获取自己定义的属性用document.getElementByID("TD1").getA" />

javascript IE与FireFox 一些兼容写法

系统 3188 0

1>获取控件用document.getElementById,不用document.all(FF等浏览器不支持)
2><button> 会被firefox解释为提交form或者刷新页面,需要写标准<button type="button">
3>使用childNode()代替之前的children 
4> 手型鼠标指针请用cursor:pointer,不用 cursor:hand
5>获取自己定义的属性 用  document.getElementByID("TD1").getAttribute("isOBJ")  代替document.getElementByID("TD1").isOBJ
6>事件追加方法attachEvent(IE)/detachEvent;addEventListener( Mozilla, Netscape, Firefox)/removeEventListener
  又或者直接用obj.onmouseover=func;
7>Firefox中不存在 Event时间,必须通过object本身去取
   在Firefox获取当前物件的坐标方法:
  document.onmousemove = Inti_move;
  function  Inti_move(ert)
{
  x=ert.pageX;
}

Internet Explorer Name Mozilla Name Description 表4 Mozilla与IE之间的事件属性差异
altKey altKey Boolean property that returns whether the alt key was pressed during the event.
cancelBubble stopPropagation() Used to stop the event from bubbling farther up the tree.
clientX clientX The X coordinate of the event, in relation to the element viewport.
clientY clientY The Y coordinate of the event, in relation to the element viewport.
ctrlKey ctrlKey Boolean property that returns whether the Ctrl key was pressed during the event.
fromElement relatedTarget For mouse events, this is the element from which the mouse moved away.
keyCode keyCode For keyboard events, this is a number representing the key that was pressed. It is 0 for mouse events.
returnValue preventDefault() Used to prevent the event's default action from occurring.
screenX screenX The X coordinate of the event, in relation to the screen.
screenY screenY The Y coordinate of the event, in relation to the screen.
shiftKey shiftKey Boolean property that returns whether the Shift key was pressed during the event.
srcElement target The element to which the event was originally dispatched.
toElement currentTarget For mouse events, this is the element to which the mouse moved.
type type Returns the name of the event.


8>event.keyCode的問題解決
在FF中不存在window.event.keyCode屬性。可以用以下方法解決

function  keepKeyNum(evt)
{
 
var   k = window.event ? evt.keyCode:evt.which;
     
if  ((k <= 57 &&  (k >= 48 ))
{ return   true ;}
     
else  
{ return   false ;}

  < input  type ="text"  onKeyPress =" return keepKeyNum(event);"   >

javascript IE与FireFox 一些兼容写法


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论