object.insertAdjacentHTML 如何使用?并附上多文件上传的例子
2006-11-10 11:03
609 查看
insertAdjacentHTMLMethod
InsertsthegivenHTMLtextintotheelementatthelocation.Syntax
object.insertAdjacentHTML(sWhere,sText)
Parameters
sWhere | Required.StringthatspecifieswheretoinserttheHTMLtext,usingoneofthefollowingvalues:
| ||||||||
sText | Required.StringthatspecifiestheHTMLtexttoinsert.ThestringcanbeacombinationoftextandHTMLtags.Thismustbewell-formed,validHTMLorthismethodwillfail. |
ReturnValue
Noreturnvalue.
Remarks
IfthetextcontainsHTMLtags,themethodparsesandformatsthetextasitisinserted.
Youcannotinserttextwhilethedocumentisloading.Waitforthe
WhenusingtheinsertAdjacentHTMLmethodtoinsertscript,youmustincludethe
Example
ThisexampleusestheinsertAdjacentHTMLmethodtoinsertscriptintothepage.
varsHTML="<inputtype=buttononclick="+ "go2()"+"value='ClickMe'><BR>" varsScript='<SCRIPTDEFER>' sScript=sScript+ 'functiongo2(){alert("Hellofrominsertedscript.")}' sScript=sScript+'</script'+'>'; ScriptDiv.insertAdjacentHTML("afterBegin",sHTML+sScript);
SeeAlsoinnerHTML, insertAdjacentText, outerHTML
object.insertAdjacentHTML(sWhere,sText)
在object标签内的指定位置插入HTML代码
sWhere:插入位置
如果object为<div>
beforeBegin在object标签的前端(在<div>之前)
afterBegin在object标签里的最前端(在<div>之后)
beforeEnd在object标签里的最后端(在</div>之前)
afterEnd在object标签的后面(在</div>之后)
sText要插入的HTML代码
=======================================
C#
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<title>uploadFile</title>
<metacontent="MicrosoftVisualStudio7.0"name="GENERATOR">
<metacontent="C#"name="CODE_LANGUAGE">
<metacontent="JavaScript"name="vs_defaultClientScript">
<metacontent="http://schemas.microsoft.com/intellisense/ie5"name="vs_targetSchema">
<LINKhref="css/css.css"type="text/css"rel="stylesheet">
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</HEAD>
<bodybgColor="#939ba2"leftMargin="4"topMargin="0">
<tablewidth="600"align="center">
<tr>
<tdheight="18"></td>
</tr>
<tr>
<td>
<formid="FileUp"method="post"encType="multipart/form-data"runat="server">
<tableclass="3dup"height="87"cellSpacing="0"cellPadding="0"width="460"align="center"border="0">
<tr>
<tdcolSpan="3"> </td>
</tr>
<tr>
<tdcolSpan="3">
<divalign="center">上传录入文字文档<br>
<hr>
</div>
</td>
</tr>
<tr>
<tdheight="20">
<divalign="left"><FONTface="宋体"> 项目名称:</FONT></div>
</td>
<tdcolSpan="2"height="20"><asp:labelid="pname"runat="server"ForeColor="White"></asp:label><asp:labelid="pid"runat="server"Visible="False"></asp:label></td>
</tr>
<tr>
<tdwidth="69"height="20">
<divalign="left"><FONTface="宋体"> 录 入 员:</FONT></div>
</td>
<tdwidth="391"colSpan="2"height="20"><asp:labelid="iman"runat="server"ForeColor="White"></asp:label></td>
</tr>
<tr>
<tdalign="middle"colSpan="3"height="20">
<hr>
<inputclass="mybutton"onclick="addFile()"type="button"value="增加上传文件">
<inputclass="mybutton"id="reset"type="reset"value="重新设置"runat="server">
<asp:buttonid="Button1"runat="server"CssClass="mybutton"Text="立即上传"></asp:button>
<inputclass="mybutton"onclick="history.back();"type="button"value="返回"name="Button">
<br>
<hr>
<Pid="MyFile"> <INPUTclass="box_m"type="file"size="50"name="File">
<br>
</P>
</td>
</tr>
<tr>
<tdcolSpan="3">
</td>
</tr>
<tr>
<tdcolSpan="3"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</HTML>
注意:还有2个方法:
oElement=object[b].insertAdjacentElement(sWhere,oElement)
object[b].insertAdjacentHTML(sWhere,sText)
用法基本一样。
[/b]
[/b]