-1

我有以下代码将文本设置为输入框:

private void messageToolStripMenuItem_Click(object sender, EventArgs e)
            {
                HtmlDocument doc = this.webBrowser1.Document;
                doc.GetElementsByTagName("input")
                    .GetElementsByName("message_id")
                    [0].SetAttribute("value", "Whats up");
            }

这是那个输入框的信息

<!-- Quick Message -->
        <br />
        <div id="quick-message">
            <form action="sendmessage.aspx" method="post" name="sendmessage">

            <input type="hidden" name="7e27a05c" value="369dd5604f64ea23be41fe37ac416276" />
            <input type="hidden" name="sguid" value="DECBD1FF570BA8D09B642734AA677B8731ABD318F67AF409519BEE228762D38CD62B6F2051F36ADAF50861146F83036C2294FC948945A200DEAE9D6C7A70FA795573066C96A8124F9FD18EB3B8D4C1B983BA81C426D644C6716C067C29FA917943115D5726F7AEFEC7E88C16F8F1FFA78B6A881F37EEA61B8475D148D5CB1D9797495F380612D0D35782C32333526C4D2FE047AD1A8044D808E07C18D190999561A68C205546363F3B624FDB40F65F54187FC89C6327918A3FE595F152C0FD41433C4FB07F0CD69EDB3BE615AE08A48A"/>

            <input type="hidden" name="autologinid" value="ayxwntt5met1yv0o0o0i5ctj" />
            <input type="hidden" name="message_id" value="" />
            <input type="hidden" name="u" value="3FF3XX" />

            <input type="hidden" value="44696155" name="p_id" />

            <input type="hidden" name="reciever" value="sarita_j" />
            <input type="hidden" value="44696155" name="profile_idb" />
            <input type="hidden" value="48936882" name="usersendtob" />
            <input type="hidden" name="i" value="59181062" />
            <input type="hidden" name="v" value="13" />
            <center>
                <span class="headline txtBlue size16">Send a Quick Message!</span>
                <input maxlength="40" name="subject" size="33" type="hidden" value="Hi" />
                <center>
                    <textarea class="profile" name="message"></textarea><br />
                    <input type="submit" class="button norm-green" style="" value="Send Quick Msg" name="sendmessage" /></center>
            </form>

但是,当我单击按钮时,什么也没有发生。有任何想法吗?

4

1 回答 1

0

为什么不像这样遍历 DOM:

    HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("input");
    foreach (HtmlElement elem in elems)
    {

        if ( elem.GetAttribute("name")=="message_id")
        {
          elem.SetAttribute("value","what's up");
        }
    }
于 2013-05-16T23:23:01.930 回答