JS手动创建标签

代码;

<html>
<head>
<title>js标签属性的添加</title>
<script >
function setxxx(){
alert("xx");
 var box = document.getElementById("box"); 
var oLi = document.createElement("li"); 
var oH3 = document.createElement("h3");
oH3.innerHTML = "这是js生成的一个h3的标签";
oH3.style.height="30px";
oH3.style.background = "red";    
oH3.setAttribute('class','dtime');
box.appendChild(oH3);


}

</script>
</head>
<div id="box">
<input type="button" value="点击" onclick="setxxx()" />
</div>

<body>

</body>

</html>

截图:

posted on 2016-02-26 23:38  手撕高达的村长  阅读(322)  评论(0编辑  收藏  举报

导航