js在兼容IE和FireFox方面的一些方法

| |
时间: 不指定 2008/04/08 11:33 , 作者: 邢磊
1、创建一个Element,通用的写法为createElement("div")
   IE中也可以这样写
createElement("<div style='color:#FFFFFF'>")
,但Firefox不认
2、IE中的width、height与Firefox中概念不同,IE中width=FireFox中的width+2*borderWidth+2*Padding
3、动态添加css代码
   IE:
cssStr = "p { color:#FF0000;} a { font-size:9pt;}";
var style = win.document.createStyleSheet();
style.cssText = cssStr;


FireFox:
cssStr = "p { color:#FF0000;} a { font-size:9pt;}";
var style = win.document.createElement("style");
style.type = "text/css";
style.innerHTML = cssStr;
win.document.getElementsByTagName("HEAD").item(0).appendChild(style);


4、table在后面添加加行或列,通用写法insertRow(-1),insertCell(-1)
   IE中insertRow(),insertCell()这样写也可以,Firefox不认
5、警告对话框alert(),IE中书写时无参数则默认参数为空字符串,Firefox中则必须输入参数,传空参数则要写成alert("");
6、给element.style.width赋值必须写成24px,只写数字24的话,FireFox会不认,IE里都可以
7、在使用Element,并给其绑定了onclick、onmouseover、onmousedown、onmouseout等事件
    
element.onclick = function() { alert("hello kitty"); };

   时,需注意
   将此元素添加到上级元素上时要用appendChild,不可以在上级中使用innerHTML操作,这样会使事件无效
  • 中查看更多“js在兼容IE和FireFox方面的一些方法”相关内容
  • 中查看更多“js在兼容IE和FireFox方面的一些方法”相关内容
  • 中查看更多“js在兼容IE和FireFox方面的一些方法”相关内容

  • 最后编辑: 邢磊 编辑于2008/04/08 12:51
    类别:D/XHTML::CSS | Tags: , , | 0 条评论, 410 次阅读
    网友评论(0):
    发表评论
    表情
    emotemotemotemot
    emotemotemotemot
    emotemotemotemot
    emotemotemotemot
    emotemotemotemot
    emotemotemotemot
    emotemotemotemot
    emotemotemotemot
    打开HTML
    打开UBB
    打开表情
    隐藏
    昵称   密码   游客无需密码
    网址   电邮   [注册]
                   

    验证码 不区分大小写