object.insertAdjacentHTML 如何使用?并附上多文件上传的例子

insertAdjacentHTML Method


Inserts the given HTML text into the element at the location.

Syntax

object.insertAdjacentHTML(sWhere, sText)

Parameters

sWhereRequired. String that specifies where to insert the HTML text, using one of the following values:
beforeBeginInserts sText immediately before the object.
afterBeginInserts sText after the start of the object but before all other content in the object.
beforeEndInserts sText immediately before the end of the object but after all other content in the object.
afterEndInserts sText immediately after the end of the object.
sTextRequired. 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 Value

No return value.

Remarks

If 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.

When using the insertAdjacentHTML method to insert script, you must include the DEFER attribute in the script element.

Example

This example uses the insertAdjacentHTML method to insert script into the page.

var sHTML="<input type=button οnclick=" +
"go2()" + " value='Click Me'><BR>"
var sScript='<SCRIPT DEFER>'
sScript = sScript +
'function go2(){ alert("Hello from inserted script.") }'
sScript = sScript + '</script' + '>';
ScriptDiv.insertAdjacentHTML("afterBegin",sHTML + sScript);
 
 
  

See Also

innerHTML, 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#
ExpandedBlockStart.gif ContractedBlock.gif   <% dot.gif @   Page   language="c#"   Codebehind="uploadFile.aspx.cs"   AutoEventWireup="false"   Inherits="OneForm.uploadFile"    %>    
None.gif  
<! DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN"    >    
None.gif  
< HTML >    
None.gif  
< HEAD >    
None.gif  
< title > uploadFile </ title >    
None.gif  
< meta    content ="Microsoft   Visual   Studio   7.0"    name ="GENERATOR" >    
None.gif  
< meta    content ="C#"    name ="CODE_LANGUAGE" >    
None.gif  
< meta    content ="JavaScript"    name ="vs_defaultClientScript" >    
None.gif  
< meta    content ="http://schemas.microsoft.com/intellisense/ie5"    name ="vs_targetSchema" >    
None.gif  
< LINK    href ="css/css.css"    type ="text/css"    rel ="stylesheet" >    
ExpandedBlockStart.gifContractedBlock.gif  
< script    language ="JavaScript" > dot.gif    
InBlock.gif          
function   addFile()   
ExpandedSubBlockStart.gifContractedSubBlock.gif          
dot.gif{   
InBlock.gif          
var   str   =   '&nbsp;&nbsp;&nbsp;<INPUT   type="file"   size="50"   NAME="File"     class="box_m"><br>'   
InBlock.gif          document.getElementById('MyFile').insertAdjacentHTML(
"beforeEnd",str)   
ExpandedSubBlockEnd.gif          }
   
ExpandedBlockEnd.gif  
</ script >    
None.gif  
< meta    http-equiv ="Content-Type"    content ="text/html;   charset=gb2312" >    
None.gif  
</ HEAD >    
None.gif  
< body    bgColor ="#939ba2"    leftMargin ="4"    topMargin ="0" >    
None.gif  
< table    width ="600"    align ="center" >    
None.gif  
< tr >    
None.gif  
< td    height ="18" ></ td >    
None.gif  
</ tr >    
None.gif  
< tr >    
None.gif  
< td >    
None.gif  
< form    id ="FileUp"    method ="post"    encType ="multipart/form-data"    runat ="server" >    
None.gif  
< table    class ="3dup"    height ="87"    cellSpacing ="0"    cellPadding ="0"    width ="460"    align ="center"    border ="0" >    
None.gif  
< tr >    
None.gif  
< td    colSpan ="3" > &nbsp; </ td >    
None.gif  
</ tr >    
None.gif  
< tr >    
None.gif  
< td    colSpan ="3" >    
None.gif  
< div    align ="center" > 上传录入文字文档 < br >    
None.gif  
< hr >    
None.gif  
</ div >    
None.gif  
</ td >    
None.gif  
</ tr >    
None.gif  
< tr >    
None.gif  
< td    height ="20" >    
None.gif  
< div    align ="left" >< FONT    face ="宋体" > &nbsp; 项目名称: </ FONT ></ div >    
None.gif  
</ td >    
None.gif  
< td    colSpan ="2"    height ="20" >< asp:label    id ="pname"    runat ="server"    ForeColor ="White" ></ asp:label >< asp:label    id ="pid"    runat ="server"    Visible ="False" ></ asp:label ></ td >    
None.gif  
</ tr >    
None.gif  
< tr >    
None.gif  
< td    width ="69"    height ="20" >    
None.gif  
< div    align ="left" >< FONT    face ="宋体" > &nbsp; &nbsp; &nbsp; 员: </ FONT ></ div >    
None.gif  
</ td >    
None.gif  
< td    width ="391"    colSpan ="2"    height ="20" >< asp:label    id ="iman"    runat ="server"    ForeColor ="White" ></ asp:label ></ td >    
None.gif  
</ tr >    
None.gif  
< tr >    
None.gif  
< td    align ="middle"    colSpan ="3"    height ="20" >    
None.gif  
< hr >    
None.gif  
< input    class ="mybutton"    onclick ="addFile()"    type ="button"    value ="增加上传文件" >     &nbsp;    
None.gif  
< input    class ="mybutton"    id ="reset"    type ="reset"    value ="重新设置"    runat ="server" >     &nbsp;    
None.gif  
< asp:button    id ="Button1"    runat ="server"    CssClass ="mybutton"    Text ="立即上传" ></ asp:button > &nbsp;    
None.gif  
< input    class ="mybutton"    onclick ="history.back();"    type ="button"    value ="   返   回   "    name ="Button" >    
None.gif  
< br >    
None.gif  
< hr >    
None.gif  
< P    id ="MyFile" > &nbsp;&nbsp;     < INPUT    class ="box_m"    type ="file"    size ="50"    name ="File" >    
None.gif  
< br >    
None.gif  
</ P >    
None.gif  
</ td >    
None.gif  
</ tr >    
None.gif  
< tr >    
None.gif  
< td    colSpan ="3" > &nbsp;    
None.gif  
</ td >    
None.gif  
</ tr >    
None.gif  
< tr >    
None.gif  
< td    colSpan ="3" ></ td >    
None.gif  
</ tr >    
None.gif  
</ table >    
None.gif  
</ form >    
None.gif  
</ td >    
None.gif  
</ tr >    
None.gif  
</ table >    
None.gif  
</ body >    
None.gif  
</ HTML >    
None.gif

注意:还有2个方法:
oElement = object.insertAdjacentElement(sWhere, oElement)
object.insertAdjacentHTML(sWhere, sText)
用法基本一样。

转载于:https://www.cnblogs.com/genson/archive/2006/11/10/556292.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值