删除网页中的表格行的问题(100分)

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

jieson

Unregistered / Unconfirmed
GUEST, unregistred user!
我的代码如下<br><br>procedure TIEForm.Button5Click(Sender: TObject);<br>var<br>&nbsp; doc:IHTMLDocument2;<br>&nbsp; all:IHTMLElementCollection;<br>&nbsp; len,i:integer;<br>&nbsp; item:IHTMLElement;<br>&nbsp; it: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) = 'b' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; it:=item;<br>&nbsp; &nbsp; &nbsp; &nbsp; it.deleteRow(1);<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>这样做可以删除表b的第一行<br>但是我想删除id为‘1’的行该怎么办啊?<br>怎么知道第几行的id是1呢?
 
被大水冲跑了,自己顶一下吧
 
没人理我,只好自己再顶一下了
 
以下能删除,但删除后会报错!<br><br>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,j:integer;<br>&nbsp; item:IHTMLElement;<br>&nbsp; it,newIt,x: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; x:=it.all.tags('TR').length;<br>&nbsp; &nbsp; &nbsp; &nbsp; for j:=x-1 downto 0 do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if it.all.tags('TR').item(j).id='1' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; it.deleteRow(j);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br><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 id='1'&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 id='2'&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;TR id='2'&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>
 
我刚才试了一下,没错啊<br>我试一下在什么情况下会出错先
 
接受答案了.
 

Similar threads

后退
顶部