-1

我需要获取标签的偏移位置...我 HtmlElementCollection sp = textwebBrowser1.Document.GetElementsByTagName("span"); 用来获取跨度标签的集合....但在某些情况下,即使我在页面中有跨度标签,集合的计数为零...我猜这是因为一些带有图像信息的对象标签...例如-

在这种情况下,我不知道如何检索 span 标签的偏移量

HTML 代码:

<HTML><BODY>.....Using <OBJECT> and <EMBED><HTML><HEAD><TITLE>A Web page with a rolling die</TITLE></HEAD><BODY><OBJECT ID="Dieroll1"CLASSID="CLSID:46646B43-EA16-11CF-870C-00201801DDD6"CODEBASE="diero‌​ll.cab#Version=1,0,0,1"WIDTH="200"HEIGHT="200"><PARAM NAME="ForeColor" VALUE="0"><PARAM NAME="BackColor" VALUE="16777215"><PARAM NAME="Image" VALUE="beans.bmp"><EMBED LIVECONNECT NAME="Dieroll1"WIDTH="200"HEIGHT="200"CLASSID="CLSID:46646B43-EA16-11CF-870C-002‌​01801DDD6"TYPE="application/oleobject"CODEBASE="dieroll.cab#Version=1,0,0,1"PARAM‌​_ForeColor="0"PARAM_BackColor="16777215"></OBJECT><BR>Hthe die</BODY></HTML>Arrange to run Explorer when you debug the control.Here's the syntax for an OBJECT tag that sets the Image property:<OBJECTCLASSID="clsid:46646B43-EA16-11CF-870C-00201801DDD6"CODEBASE="http://www.gregcons.com/test/dieroll.ocx"ID=die1WIDTH=200HEIGHT=200ALIGN=centerHSPACE=0VSPACE=0><PARAM NAME="Dots" VALUE="1"><PARAM NAME="Image" VALUE="http://www.gregcons.com/test/beans.bmp">and the <span style='background-color: rgb(255, 255, 0);'>image</span> file you are using....</BODY></HTML>
4

2 回答 2

0

为 span 标签提供一个 id 并使用

document.getElementById('id')

于 2013-02-13T06:39:08.253 回答
0

我在你的问题中使用了你的 html 代码,我得到了所有带有以下代码的 span 标签:(代码必须在页面加载后运行)

 void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        List<HtmlElement> spanelement = new List<HtmlElement>();
        foreach (HtmlElement span in webBrowser1.Document.GetElementsByTagName("span"))
        {
            spanelement.Add(span);
            //Or Add Offset
            //spanelement.Add(span.OffsetRectangle.Top;);
        }
    }
于 2013-02-13T09:14:13.540 回答