关于在网页中动态添加表格行的问题。(100分)

  • 主题发起人 主题发起人 jieson
  • 开始时间 开始时间
J

jieson

Unregistered / Unconfirmed
GUEST, unregistred user!
我的代码如下:<br>procedure TIEForm.Button4Click(Sender: TObject);<br><br>var<br>&nbsp; doc:IHTMLDocument2;<br>&nbsp; all:IHTMLElementCollection;<br>&nbsp; len,i:integer;<br>&nbsp; item:IHTMLElement;<br>begin<br>&nbsp; if Assigned(IEThis)then<br>&nbsp; begin<br>&nbsp; &nbsp; doc:=IEThis.Document as IHTMLDocument2;<br><br>&nbsp; &nbsp; //获得文档中所有的HTML元素集合<br>&nbsp; &nbsp; all:=doc.Get_all;<br><br><br>&nbsp; &nbsp; len:=all.Get_length;<br><br>&nbsp; &nbsp; //访问HTML元素集合中的每一个元素<br>&nbsp; &nbsp; for i:=0 to len-1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; item:=all.item(i,varempty) as IHTMLElement;<br>&nbsp; &nbsp; &nbsp; //a为表格id <br>&nbsp; &nbsp; &nbsp; if item.getAttribute('id',0) = 'a' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; item.insertAdjacentHTML('AfterEnd','&lt;TR id=3&gt;&lt;TD id=31&gt;333&lt;/TD&gt;&lt;TD id=32&gt;333&lt;/TD&gt;&lt;TD id=33&gt;333&lt;/TD&gt;&lt;/TR&gt;');//问题就出在这个beforeend上了,如果是afterend就没有问题,但是在表格外添加&lt;tr&gt;和&lt;td&gt;是不行的<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>谁对ie给出的那些接口熟啊,帮帮忙吧!分不够可以加的。
 
这么快就冲到第二篇了!
 
procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; IEThis.Navigate('d:/temp.htm');<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; doc:IHTMLDocument2;<br>&nbsp; all:IHTMLElementCollection;<br>&nbsp; len,i:integer;<br>&nbsp; item:IHTMLElement;<br>&nbsp; it,newIt:variant;<br>begin<br>&nbsp; if Assigned(IEThis)then<br>&nbsp; begin<br>&nbsp; &nbsp; doc:=IEThis.Document as IHTMLDocument2;<br>&nbsp; &nbsp; all:=doc.Get_all;<br>&nbsp; &nbsp; len:=all.Get_length;<br>&nbsp; &nbsp; for i:=0 to len-1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; item:=all.item(i,varempty) as IHTMLElement;<br>&nbsp; &nbsp; &nbsp; if item.getAttribute('id',0) = 'a' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; it:=item;<br>&nbsp; &nbsp; &nbsp; &nbsp; newIt:=it.insertRow(it.rows.length);<br>&nbsp; &nbsp; &nbsp; &nbsp; newIt.id:='3';<br>&nbsp; &nbsp; &nbsp; &nbsp; it:=newIt.insertCell(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; it.innertext:='1111';<br>&nbsp; &nbsp; &nbsp; &nbsp; it:=newIt.insertCell(1);<br>&nbsp; &nbsp; &nbsp; &nbsp; it.innertext:='2222';<br>&nbsp; &nbsp; &nbsp; &nbsp; it:=newIt.insertCell(2);<br>&nbsp; &nbsp; &nbsp; &nbsp; it.innertext:='33333';<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br><br>以下是测试文档 d:/temp.htm<br><br>&lt;HTML&gt;<br>&lt;HEAD&gt;<br>&lt;TITLE&gt; New Document &lt;/TITLE&gt;<br>&lt;/HEAD&gt;<br>&lt;BODY&gt;<br>&lt;font &gt;aaa&lt;/font&gt;<br>&lt;TABLE id='a' border=1&gt;<br> &lt;TR&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;2222222&lt;/TD&gt;&lt;TD&gt;3333333&lt;/TD&gt;&lt;/TR&gt;<br> &lt;TR&gt;&lt;TD&gt;bbbbb&lt;/TD&gt;&lt;TD&gt;bbb&lt;/TD&gt;&lt;TD&gt;cccc&lt;/TD&gt;&lt;/TR&gt;<br>&lt;/TABLE&gt;<br>&lt;font &gt;aaa&lt;/font&gt;<br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br>
 
又是你老兄帮忙,太感谢了!
 
接受答案了.
 
后退
顶部