通过JS设置元素属性.
obj.setAttribute("style","background:#333");
obj.style.cssText="background:#333";(IE)
同时使用可以实现在各个浏览器上兼容.
通过JS设置元素class属性.
第一种方法:
obj.setAttribute("class","ak47");
obj.setAttribute("className","ak47");(IE)
第二种方法:
obj.className="ak47";
可以实现在各个浏览器上兼容.
通过JS为元素属性添加事件.
obj.setAttribute("onclick","dofn()");(IE不理解)
obj.onclick=funciont(){dofn();}可以实现在各个浏览器上兼容
通过JS创建单选按钮.
obj.setAttribute("type","radio");obj.setAttribute("name","girl");obj.setAttribute("value","0");
obj=document.createElement("<input type='radio' name='girl' value='0'>");(IE)
if(document.udiqueID){//IE独有;
obj=document.createElement("<input type='radio' name='girl' value='0'>");
}else{
obj.setAttribute("type","radio");
obj.setAttribute("name","girl"); obj.setAttribute("value","0");
}
obj.setAttribute("style","background:#333");
obj.style.cssText="background:#333";(IE)
同时使用可以实现在各个浏览器上兼容.
通过JS设置元素class属性.
第一种方法:
obj.setAttribute("class","ak47");
obj.setAttribute("className","ak47");(IE)
第二种方法:
obj.className="ak47";
可以实现在各个浏览器上兼容.
通过JS为元素属性添加事件.
obj.setAttribute("onclick","dofn()");(IE不理解)
obj.onclick=funciont(){dofn();}可以实现在各个浏览器上兼容
通过JS创建单选按钮.
obj.setAttribute("type","radio");obj.setAttribute("name","girl");obj.setAttribute("value","0");
obj=document.createElement("<input type='radio' name='girl' value='0'>");(IE)
if(document.udiqueID){//IE独有;
obj=document.createElement("<input type='radio' name='girl' value='0'>");
}else{
obj.setAttribute("type","radio");
obj.setAttribute("name","girl"); obj.setAttribute("value","0");
}