Zim*_*imo 3 javascript webview2
我试图理解 WebView2 中的架构。使用 WebBrowser,我曾经从 GetElementById 返回的结果中获取属性,如下所示:Document.GetElementById("DropDownList").GetAttribute("selectedIndex")
我知道ExecuteScriptAsyncWebView2 中的 可以运行 JavaScript 并以字符串形式返回结果。但是,它看起来不知道如何从元素获取属性。下面的代码返回一个空值。尽管如此, getElementById 返回正确的结果。
ExecuteScriptAsync("document.getElementById('DropDownList').getAttribute('selectedIndex')")
我的语法不正确吗?如何获取WebView2中的属性?我们是否必须在脚本中编写一个函数并从主机调用它?
谢谢
AHTMLSelectElement没有名为“selectedIndex”的属性。它有一个名为“selectedIndex”的属性。
像这样称呼它WebView2:
await webView21.ExecuteScriptAsync("document.getElementById('DropDownList').selectedIndex");
Run Code Online (Sandbox Code Playgroud)
许多人对 javascriptattributes和properties. 简单的规则(容易记住)是:
属性可以直接写在html标签中,如'id','name'等。属性由运行时设置。
| 归档时间: |
|
| 查看次数: |
7823 次 |
| 最近记录: |