var
IEfix = {
acceptcharset:
"acceptCharset"
,
accesskey:
"accessKey"
,
allowtransparency:
"allowTransparency"
,
bgcolor:
"bgColor"
,
cellpadding:
"cellPadding"
,
cellspacing:
"cellSpacing"
,
"class"
:
"className"
,
colspan:
"colSpan"
,
checked:
"defaultChecked"
,
selected:
"defaultSelected"
,
"for"
:
"htmlFor"
,
frameborder:
"frameBorder"
,
hspace:
"hSpace"
,
longdesc:
"longDesc"
,
maxlength:
"maxLength"
,
marginwidth:
"marginWidth"
,
marginheight:
"marginHeight"
,
noresize:
"noResize"
,
noshade:
"noShade"
,
readonly:
"readOnly"
,
rowspan:
"rowSpan"
,
tabindex:
"tabIndex"
,
valign:
"vAlign"
,
vspace:
"vSpace"
}
IE不能用setAttribute为dom元素设置onXXX属性,换言之,不能用setAttribute设置事件。
setAttribute bug By 司徒正美
用setAttribute设置事件
在IE下文本域获得焦点后并没有弹出预期的alert!
IE要直接赋给一个函数!
var
body = document.body;
var
form = document.createElement(
"form"
);
form.innerHTML =
""
body.appendChild(form);
if
(!+
"\v1"
){
form.elements.test.setAttribute(
"onfocus"
,
function
(){alert(
this
.name)});
}
else
{
form.elements.test.setAttribute(
"onfocus"
,
"alert(this.name)"
);
}
setAttribute bug By 司徒正美
IE用setAttribute设置事件要直接赋函数!
在IE6与IE7中也不能用setAttribute设置样式:dom.setAttribute("style","font-size:14px")
setAttribute bug By 司徒正美
IE6与IE7看不到效果!
这时要统一用dom元素的style.csstext属性赋值比较安全。
setAttribute bug By 司徒正美
h3.style.setAttribute('cssText', styleData);
总结:各个浏览器的标准的不统一确实给我们在网站制作的过程中带来很多的麻烦,遇到这种问题也是我们特别头痛的事情,这时我们试着换一种思路来考虑问题,可能也会得到异曲同工之妙。最后,我个人感觉这个问题也并不能说是IE浏览器的问题,只能说w3c在制定标准的时候欠缺全面的考虑!逼近很多标签是IE浏览器制定的。