C# windows phone 8.1 WebView 中的 InvokeMember

C# windows phone 8.1 InvokeMember in WebView

我有一个 URL 有这个 HTML 代码

<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 中的那个按钮?

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

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

确保 HTML 已加载到您的 WebView 中,否则会引发异常。