![](/img/trans.png)
[英]How to change the editable ComboBox's text to something else when a specific ComboBoxItem is selected?
[英]How to replace whole HTMLElement's text to something else?
这是例子。
webBrowser1.Document.Body.InnerHtml包含:
<img id="image1" src="myImage.gif">
在MyWebBrowser类中,我想将整个img标签重新映射为某些文本,例如字符串:“&ltmyImage&gt”(如果用户不想看到图像,我的聊天应用程序需要它)
我以为我可以做这样的事情:
Document.GetElementById("image1").InnerHtml = "<" + Document.GetElementById("image1").GetAttribute("src") + ">";
但它引发异常。
实际上,我通过在整个文档中搜索这些特定标签并使用String类的方法替换了它们来解决了该问题,但是代码看起来并不好。 如果有更有效的方法可以做到,请不要回答我的问题。
您可以使用OuterHtml属性:
HtmlElement image = Document.GetElementById("image1");
image.OuterHtml = "<" + image.GetAttribute("src") + ">";
但是请注意,分配给OuterHtml
将使对该元素的引用无效,因此image
将不再引用新内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.