문제

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 점검 된 속성을 부울로 노출시킵니다

다른 팁

평범한 JavaScript에서는 확인란 요소가 있습니다 checked 재산. 따라서 [평범한 JavaScript에서] 당신은 다음을 쓸 수 있습니다.

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

나는 .NET 또는 당신이 거기에서 사용하는 것을 모르지만 비슷한 방식으로 그것을 할 수 있습니다.

스티브

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top