js的兼容
1、属性href,在IE6、7下则返回的是全路径,修正方法是设置getAttribute第二个参数为2(期望严格按照文档设置的属性值返回,只有IE会识别第二个参数);
2、width和height不是行内的样式,不可以使用ele.getAttribute(“”)获取,应使用ele.offsetWidth获取,但是offsetWidth获取到的值包含padding+width;
3、select默认option的selected是否为true,当在html文档直接写的时候第一个selected为true,但是在IE下通过js插入一段select,则第一默认option的selected是false,解决方法:执行parent.selectedIndex,之后就OK;
4、<div style="top: 1px;"></div>
行内样式style获取ele.style,但是在IE6、7支持ele.style.cssText则返回style行内样式的值;
5、setgetAtrribute在IE6、7获取内联属性时,不支持html属性支持DOM属性,比如ele.getAttribute(“class”),在IE6、7无法获取到,需要的是className。修正方法:
var fixSpecified = {
name: true,
id: true
};
function get(ele, name) {
var ret = ele.getAttributeNode(name);
return ret && (fixSpecified[name] ? ret.nodeValue = "" : ret.specified) ? ret.nodeValue : undefined;
}