如何使用mshtml将复选框设置为"已选中"?

MrG*_*les 2 .net html c# 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
     }
}
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助!

格雷格

Jer*_*emy 5

HTMLInputElement将Checked属性公开为布尔值