例 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.onload=function(){ var para = document.createElement("p"); /*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
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。