我可以使用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属性公开为布尔

其他提示

在纯JavaScript中,复选框元素具有 checked 属性。所以[在普通的JavaScript中]你可以写:

document.getElementById("myCheckbox").checked = true;

我不知道.NET或者你在那里使用的任何东西,但他们可能会以类似的方式进行。

史蒂夫

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top