javascript当中createElement的用法
例 1.2(CreateP&InputIEFF.html)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<style type="text/css">
.test {
background:#0000FF;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.οnlοad=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>
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/102652111