html 如何隐藏class,mshtml.HTMLDocument如何使用class属性隐藏动态创建的div

3 个答案:

答案 0 :(得分:3)

这是我根据你的描述使用的方法,它工作正常。

public MainForm()

{

InitializeComponent();

webBrowser.DocumentCompleted += webBrowser_DocumentCompleted;

var text = @"

hello everyone!

";

webBrowser.DocumentText = text;

}

void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

var doc = webBrowser.Document.DomDocument as IHTMLDocument2;

var styleSheet = doc.createStyleSheet(string.Empty, 0);

var ruleIndex = styleSheet.addRule(".backgroundImageDivsClass", "display:none", 0);//index can be used to remove the rule

//styleSheet.cssText = @".backgroundImageDivsClass{display:none;}";

}

答案 1 :(得分:2)

styleSheet.cssText = @".backgroundImageDivsClass{display:none !important;}";

是我的建议吗?它会强制覆盖任何试图设置display属性的东西。 (与图像旋转器控件一样)因为任何!重要标签最后由DOM应用

如果这不起作用,请进一步帮助..

使用Firefox中的firebug插件,确定动态应用于Div的CSS属性。

您可以实时编辑firebug渲染的CSS,直到找到有效的解决方案,然后将其合并到您的解决方案中。

答案 2 :(得分:1)

我认为问题是你在Document上使用createStyleSheet方法而不是在Document.DomDocument上使用。

答案here可能是一个有用的参考。

另外,正如您可以阅读here不再支持createStyleSheet。从Internet Explorer 11开始,您应该使用document.createElement(' style')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值