Domanda

Posso fare la maggior parte delle cose che devo fare con mshtml, ma sono un po 'bloccato con il modo in cui impostare un elemento di input della casella di controllo su " controllato " ;. Ecco la situazione ...

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
     }
}

Grazie in anticipo per qualsiasi aiuto!

Gregg

È stato utile?

Soluzione

HTMLInputElement espone la proprietà Checked come un booleano

Altri suggerimenti

Nel semplice JavaScript, gli elementi della casella di controllo hanno una proprietà selezionata . Quindi [in semplice JavaScript] potresti scrivere:

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

Non conosco .NET o qualunque cosa tu stia usando lì, ma potrebbero farlo in modo simile.

Steve

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top