【问题标题】:C# windows phone 8.1 InvokeMember in WebViewC# windows phone 8.1 WebView 中的 InvokeMember
【发布时间】:2015-02-14 23:58:45
【问题描述】:

我有一个包含此 HTML 代码的 URL

<html>
  <head>
    <title>Search</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  </head>
  <body>
  <form action="http://mySite.ir/search.html" method="POST">
  <input onkeypress=FKeyPress(this); onkeydown=FKeyDown(this); size="25" type="text" name="query" value=""/>
  <input type="submit" value="Search"/>
  </form>
</html>

我想在 TextBox 上放一些东西,然后在 WebView 上按下 ClickButton。 在 C# 桌面中我使用了这段代码>

webBrowser1.Document.GetElementById("textBoxV").SetAttribute("value", textBox1.Text);
webBrowser1.Document.GetElementById("pressButton").InvokeMember("submit");

但在 windows phone 8.1 中不能使用该方法。 请告诉我如何在 windows phone 中按下那个按钮?

【问题讨论】:

    标签: c# windows-phone-8.1


    【解决方案1】:

    您可以调用 InvokeScriptAsync 并在第一个表单(索引 == 0)上调用 submit 或通过 id 获取表单然后调用 submit()。

    await wview.InvokeScriptAsync("eval", new string[] { "var elem = document.forms[0].submit();"});
    

    确保在你的 WebView 中加载了 HTML,否则会抛出异常。

    【讨论】:

    • 谢谢,但我怎样才能将消息设置到 'textBoxV' 中?
    猜你喜欢
    • 2016-12-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    相关资源
    最近更新 更多