FF和IE之间DOM的区别

1.向表中追加行:

   IE\FF:IE允许tr元素增加到tbody中,而不是直接增加到table中

<table id="myTable">
<tbody id="myTableBody"></tbody>
</table>
var cell=document.createElement("td").appendChild(document.createTextNode("foo");
var row = document.createElement("tr").appendChild(cell);
document.getElementById("mysqlTableBody").appendChild(row);

 

2.通过javascript设置元素的样式

   FF:使用setAttribute方法

var spanElement = document.getElementById("mySpan");
spanElement.setAttribute("style","font-weight:bold ; color: red;");

   IE\FF:setAttribute不起作用

var spanElement = document.getElementById("mySpan");
spanElement.style.cssText = "font-weight:blod ; color:red;";
/*或者spanElement.style.color = "red";*/

 

3.设置元素的class属性

   FF:参数"class"

var element = document.getElementById("mySpan");
element.setAttribute("class","styleClass");

   IE:参数"myClass"

var element = document.getElementById("mySpan");
element.setAttribute("className","styleClass");

   IE\FF:将class和className都作为属性名

var element = document.getElementById("myElement");
element.setAttribute("class","styleClass");
element.setAttribute("className","styleClass");

 

4.创建输入元素

   FF\IE:

var button = document.createElement("input");
button.setAttribute("type","button");
document.getElementById("formElement").appendChild(button);

 

5.向输入元素增加事件处理程序

   FF:setAttribute方法

var formElement = document.getElementById("formElement");
formElement.setAttribute("onclick","doFun();");

    FF\IE:

var formElement = document.getElementById("formElement");
formElement.onclick = function(){doFun();};

 

6.创建单选按钮

   FF:

var readioButtion = document.createElement("input");
readioButtion.setAttribute("type","radio");
readioButtion.setAttribute("name","radioButtion");
readioButtion.setAttribute("value","checked");

  IE:

var radioButtion = document.createElement("<input type='radio' name='radioButtion' value ='checked'>"); 

    FF\IE:浏览器嗅探(browser-sniffing)机制,IE能识别出名为uniqueID的document对象的专用属性。

if(document.uniqueID){
	//Internet Explorer
	var radioButtion = document.createElement("<input type='radio' name='radioButtion' value ='checked'>");
	}
	else
	{
		//Standards Compliant
		var readioButtion = document.createElement("input");
		readioButtion.setAttribute("type","radio");
		readioButtion.setAttribute("name","radioButtion");
		readioButtion.setAttribute("value","checked");
	}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值