首页 > 其他 > 详细

点击鼠标获取元素ID

时间:2014-06-14 08:38:39      阅读:370      评论:0      收藏:0      [点我收藏+]
原文:点击鼠标获取元素ID

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }


    private mshtml.HTMLDocument doc = null;



    private void Form1_Load_1(object sender, EventArgs e)
    {

        txtRecord.Items.Add("start...");
        txtRecord.Items.Add("start2...");
        webBrowser1.Navigate("http://www.google.com");
    }


    private void webBrowser1_DocumentComplete(object sender, WebBrowserDocumentCompletedEventArgs e)
    {

        txtRecord.Items.Add(e.Url.ToString() + " loaded...");

        if (doc == null)
        {
            doc = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;
            mshtml.HTMLDocumentEvents2_Event iEvent;
            iEvent = (mshtml.HTMLDocumentEvents2_Event)doc;
            iEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler(ClickEventHandler);

        }

    }

    private bool ClickEventHandler(mshtml.IHTMLEventObj e)
    {
        txtRecord.Items.Add("clicked ==>" + e.srcElement.tagName);
        txtRecord.Items.Add("clicked2 ==>" + e.srcElement.getAttribute("name", 0));

        txtRecord.Items.Add("clicked3 ==>" + e.srcElement.innerHTML);

        return true;
    }


}

 

点击鼠标获取元素ID,布布扣,bubuko.com

点击鼠标获取元素ID

原文:http://www.cnblogs.com/lonelyxmas/p/3787851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!