CSS:
/**
* @param
* @arrange (512.笔记) jb51.cc
**/
<style type="text/css">
.newDiv {
font-weight: bold;
}
</style>
html:
<script>
function clk(event) {
var parent = document.getElementById("parent");
//改变className
var child0 = document.createElement("div");
child0.innerHTML = "child0";
child0.className = "newDiv";
parent.appendChild(child0);
//改变<a href="http://jb51.cc/" title="css">css</a>Text
var child1 = document.createElement("div");
child1.innerHTML = "child1";
child1.style.<a href="http://jb51.cc/" title="css">css</a>Text = "font-weight: bold";
parent.appendChild(child1);
//改变直接样式
var child2 = document.createElement("div");
child2.innerHTML = "child2";
child2.style.fontWeight = "bold";
parent.appendChild(child2);
}
</script>
js:
/**
* @param
* @arrange (512.笔记) jb51.cc
**/
<input type="button" value="click" onclick="clk(event);"/>
<div id="parent">
<div>child</div>
</div>