关于javascript的一点注意事项,IE和FIREFOX 脚本的一些区别

十一 30 2009 Published by zdy under 编程技巧

window.addEventListener对IE不支持,IE使用window.attachEvent
但是老版本的IE就更麻烦了,至少我机子上的这个IE连attachEvent都不支持,直接用onload,onclick了。大家都支持

下面是在做sudo的时候使用的table

function creation(){
	var i,j;
	var table = document.createElement("table");
	var body = document.createElement("tbody");
	table.appendChild(body);
	for (i=1;i<10;i++){
		var tr = document.createElement("tr");
		for (j=1;j<10;j++){
			var td = document.createElement("td");
			var input = document.createElement("input");
			input.setAttribute("type","text");
			input.setAttribute("class","txt");
			input.setAttribute('className','txt');
			input.setAttribute("id","timu");
			input.setAttribute("name","timu");
			input.setAttribute("maxlength","1");
			td.appendChild(input);
			tr.appendChild(td);
		}
		body.appendChild(tr);
	}
	return table;
}

1.appendChild
其中需要注意的是,如果少了tbody这个标签,在IE中会出错

2.getElementByName
另外,因为调用每个表格时候,我用了document.getElementsByName(“timu”)
但是IE存在个bug是document.getElementsByName检索元素的ID不检索Name

3.setAttribute(‘style’,'color:red;’)
直接用object.style.color=red

4.class
input.setAttribute(“class”,”txt”);
input.setAttribute(‘className’,'txt’);//ie

No responses yet