<form name="form1">
.....
</form>
<script language="javascript">
function window.onload()
{ var input = document.createElement("INPUT");
 input.type = "text";
 input.name = "txt1";
 input.id = "txt1";
 document.form1.appendChild(input);}
</script>

解决方案 »

  1.   

    document.body.insertAdjacentHTML("beforeBegin","<input type=text name=text1>")insertAdjacentHTML Method--------------------------------------------------------------------------------Inserts the given HTML text into the element at the location.Syntaxobject.insertAdjacentHTML(sWhere, sText)ParameterssWhere Required. String that specifies where to insert the HTML text, using one of the following values: beforeBegin Inserts sText immediately before the object. 
    afterBegin Inserts sText after the start of the object but before all other content in the object. 
    beforeEnd Inserts sText immediately before the end of the object but after all other content in the object. 
    afterEnd Inserts sText immediately after the end of the object. 
     
    sText Required. String that specifies the HTML text to insert. The string can be a combination of text and HTML tags. This must be well-formed, valid HTML or this method will fail. Return ValueNo return value.ResIf the text contains HTML tags, the method parses and formats the text as it is inserted.You cannot insert text while the document is loading. Wait for the onload event to fire before attempting to call this method.As of Microsoft&reg; Internet Explorer 5, this method is accessible at run time. If elements are removed at run time, before the closing tag is parsed, areas of the document might not render.When using the insertAdjacentHTML method to insert script, you must include the DEFER attribute in the SCRIPT element.