c# - 如何使用 mshtml 将复选框设置为 "checked"?

标签 c# .net html webforms mshtml

我可以使用 mshtml 完成我需要做的大部分事情,但我对如何将复选框输入元素设置为“已选中”感到有点困惑。情况是这样的...

IHTMLElementCollection inputElements = (IHTMLElementCollection)doc.all.tags("input");
foreach (IHTMLElement el in inputElements)
{
    string elementHtml = el.outerHTML;
    string termsOfServiceIdentifier = "id=chkUTOS_ver2";

    //  select the Terms of Service checkbox
    if (elementHtml.Contains(termsOfServiceIdentifier)) 
    {
        HTMLInputElement chkTOS = (HTMLInputElement)el;
        chkTOS.@checked = true;  //  that's the solution. Thanks Wayne.
     }
     else
     {
        //  do nothing - we're not interested in this element
     }
}

预先感谢您的帮助!

格雷格

最佳答案

HTMLInputElement将 Checked 属性公开为 bool 值

关于c# - 如何使用 mshtml 将复选框设置为 "checked"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/814220/

相关文章:

c# - 为什么此代码使用异步方法?

c# - 如何获取所有连接到网络的计算机列表?

c# - 登录C#网站时出错

javascript - 试图将两个元素合二为一

html - 使用 html(不是 css?)自动调整照片大小

C# 开源 NMEA 解析器

c# - LINQ 到 SQL : how to select specific fields conditionally into DTOs (performance)

.net - 哪些 .NET 组件使用 Dispatcher?

java - 如何在不安装 MS Office 且不使用 Interop Library 的情况下读取服务器中的 MS Office 文件?

javascript - 在不使用 javascript 的情况下使内联 SVG 在浏览器中响应?