首页 > Windows开发 > 详细

Winform webbrowser 隐藏 html 元素

时间:2015-11-07 14:45:59      阅读:618      评论:0      收藏:0      [点我收藏+]

目的:用webbrowser打开网页,并隐藏网页上某个html元素

1.如果已知元素ID,比较好办

直接使用webbrowser1.Document.getElementById("id")获取元素,并修改属性

1 HTMLDocument thedocument = WebBrowser.document.all; 
2 HTMLElement theelement = thedocument.getElementById(""); //这里找你要藏的东西的ID; 
3 theelement.setAttribute("visible",false); 
4 或者
5 HtmlElement htm = webBrowser1.Document.GetElementById("控件ID"); 
6 htm.OuterHtml = ""; 

2.未知元素ID,根据Name获得元素,然后筛选出所需元素隐藏

 1 HtmlElementCollection opts = webBrowser1.Document.GetElementsByTagName("table");
 2             if (opts.Count > 0)
 3             {
 4                 foreach (HtmlElement ele in opts)
 5                 {                 
 6                     if (ele.GetAttribute("class") == "a3")
 7                     {
 8                         //opts[0].InnerHtml = ""; /*低版本IE不适用*/
 9                         opts[0].Style = "display:none";
10                     }
11                 }
12              
13             }

 

Winform webbrowser 隐藏 html 元素

原文:http://www.cnblogs.com/yt1219787097/p/4944916.html

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