[英]How to use HtmlElement in if statement [webbrowser/winforms] in c#
[英]c# webbrowser how to remove HtmlElement Attribute
我可以为WebBrowser
控件中的任何HtmlElement
调用setAttribute()
,但是如何将其删除?
是否有类似removeAttribute()
方法?
更新:
这是我的代码:
webBrowser1.Document.GetElementById("create_date_hour").SetAttribute("selected", "selected");
现在如何删除selected
属性。
在上面的代码中, selected
仅是示例。
在您发布的特定情况下(“ selected”属性),您可以尝试设置空字符串以清除该值:
webBrowser1.Document.GetElementById("create_date_hour").SetAttribute("selected", "");
我使用WinForm WebBrowser和一系列option
标签进行了尝试,并且可以正常工作。
为了完成图片,这是我的HTML测试页的代码:
<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html>
<head>
</head>
<body>
<select>
<option>OPT-01</option>
<option>OPT-02</option>
<option id="togglingOption" selected="selected">OPT-03</option>
<option>OPT-04</option>
</select>
</body>
</html>
以及我的表格的重要片段:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
void Form1_Load(object sender, EventArgs e)
{
webBrowserControl.Navigate("file:///C:/Temp/select.html");
}
private void toggle_Click(object sender, EventArgs e)
{
webBrowserControl.Document.GetElementById("togglingOption").SetAttribute("selected", "");
}
}
(表单中有一个名为“ toggle”的按钮)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.