本帖最后由 bin_520_yan 于 2011-08-09 10:50:54 编辑

解决方案 »

  1.   

    没错误,就是用InvokeMember("click")这个方法也没办法触发该事件
      

  2.   


    以下为C#代码:
    首先想WebBrowser写入一些html:
    this.webBrowser1.DocumentText = "<div class=\"ddlcont\" style=\"display: block; width: 150px; top: 414px; left: 790.75px;\"><a class=\"select\" v=\"0\" href=\"http://www.baidu.com\">不投保</a><a v=\"419000\"  onclick=   \"return   confirm( '吃饭了') \" href=\"http://www.google.com\">投保</a></div>";然后调用:
     foreach (HtmlElement item in webBrowser1.Document.All)
                {
                    if (item.GetAttribute("classname") == "ddlcont" && item.Children.Count != 0)
                    {
                        item.Children[1].ScrollIntoView(true);
                        item.Children[1].Focus();
                        item.Children[1].SetAttribute("selected", "true");
                        item.Children[1].InvokeMember("Click");
                    }
                }
    会弹出“吃饭了”的提示框,我测试过没问题,如果取消js中的提示框,则会打开a元素的href链接地址
    href赋值的时候,必须写http:\\