gpt4 book ai didi

c# - 在 WebBrowser 控件中设置 TextArea 的值 (C#/.NET)

转载 作者:太空宇宙 更新时间:2023-11-04 14:09:05 25 4
gpt4 key购买 nike

我正在寻找使用 .NET WebBrowser 控件设置 TextArea 的值。

我已经能够使用以下代码设置文本框的值(将“用户名”替换为文本框的名称):

webBrowser1.Document.All.GetElementsByName("username")[0].SetAttribute("Value", "SomeUser");

我尝试在 TextArea 上使用类似的代码(使用 GetElementById),但没有记住 TextArea 输入类型不包含“Value”属性。我还尝试设置 TextArea 的 InnerHtml 和 InnerText,但编译器在尝试设置 TextArea 输入的值时继续抛出空引用异常错误或索引越界错误。

有没有人知道如何使用 WebBrowser 控件在 TextArea 中设置文本?任何建议将不胜感激!

最佳答案

假设您有以下 HTML:

<html>
<body>
<textarea id='foo'>Testing</textarea>
</body>
</html>

您可以像这样在 textarea 中设置文本:

HtmlElement textArea = webBrowser1.Document.All["foo"];
if (textArea != null)
{
textArea.InnerText = "This is a test";
}

关于c# - 在 WebBrowser 控件中设置 TextArea 的值 (C#/.NET),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/580052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com