javascript当中createElement的用法
例 1.2(CreateP&InputIEFF.html)
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<style type="text/css">
.test {
background:#0000FF;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.onload=function(){
var para = document.createElement("p");
/*马克-to-win:the following statement para.innerHTML="qixy"; also can work.*/
// para.innerHTML="qixy";
var message = document.createTextNode("hello world");
para.appendChild(message);
para.className="test";
/* we must use the following statement, use document.appendChild(para); is wrong.马克-to-win:因为document里同时有head元素和body元素*/
document.body.appendChild(para);
/*the following statement totally can work.*/
var in1 = document.createElement("input");
in1.value="abc";
in1.id = "in1id"
document.body.appendChild(in1);
alert(""+document.getElementById("in1id").value);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>