1,前导空白
IE6,IE7,IE8的innerHTML时不会保留前导空白
var div = document.createElement(‘div‘);
div.innerHTML = " <div></div>";
return div.firstChild.nodeType === 3;
}
2,tbody
IE6,IE7会为table自动添加tbody
function tbody() {
var div = document.createElement(‘div‘);
div.innerHTML = "<table></table>";
return !!div.getElementsByTagName(‘tbody‘).length;
}
3,href,src,width,height
IE6,IE7的getAttribute会返回格式化href,src,width,height.
IE的getAttribute有两个参数,将第二个参数设为2,会严格返回文档设置是的参数
4,checkOn
检查复选框的默认值
function checkOn() {
var div = document.createElement(‘div‘);
div.innerHTML = ‘<input type="checkbox" />‘;
var input = div.getElementsByTagName(‘input‘)[0];
return input.value === ‘on‘;
}
5,cloneChecked
IE复制DOM时不会复制checked属性
function cloneChecked() {
var div = document.createElement(‘div‘);
div.innerHTML = ‘<input type="checkbox" />‘;
var input = div.getElementsByTagName(‘input‘)[0];
input.checked = true;
return input.cloneNode(true).checked;
}
6,optSelected
测试游览器下拉框默认选中的选项的selected属性是否为true
IE和早期的safari返回false
function optSelected() {
var select = document.createElement(‘select‘);
var opt = select.appendChild( document.createElement(‘option‘) );
return opt.selected;
}
7,optDisabled
测试当禁用select时,option是否会被禁用,禁用发挥false,反之返回false
function optDisabled() {
var select = document.createElement(‘select‘);
var opt = select.appendChild( document.createElement(‘option‘) );
select.disabled = true;
return opt.disabled;
}