87,914
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<style>
.divstyle {
width: 300px;
height:300px;
border: 1px solid red;
}
</style>
<script type="text/javascript">
<!--
function create(){
var odiv = document.createElement("div");
odiv.className = "divstyle";
document.body.appendChild(odiv);
}
//-->
</script>
</head>
<body>
<input type="button" value=" Create " onclick="create();" />
</body>
</html>
IE6没发现什么问题
//应该这样用
var odiv=document.createElement("div");
var att=document.createAttribute("class");
odiv.attributes.setNamedItem(att);
att.nodeValue="className"