获取Android中的html文本区域的值文本、区域、Android、html

2023-09-05 02:13:31 作者:少年范儿,)

我有一个 Html页面在的WebView 加载。有四个文本域 present在 Html页面我在的WebView加载页面后填写,当我填满了,我想获得的点击下一步 按钮文本域 在我的Andr​​oid(下一步按钮,在Android中并不在HTML页面),但是,我不能让Android中文本域 。所以,请帮助我。在此先感谢。

I have an Html page loaded on WebView. There are four TextAreas present in Html page which I fill after the page loaded on WebView and when I filled them, I want to get the values of TextAreas on click of Next Button in my Android (Next Button is in Android not in Html Page) but, I cant get the values of TextAreas in Android. So please Help me. Thanks in Advance.

下面是我装上的WebView

推荐答案

在HTML页面,链接到确定按钮:

In the HTML page, linked to an "OK" button:

function ok() {
    var t1 = document.getElementById("textarea1").value;
    var t2 = document.getElementById("textarea2").value;
    var t3 = document.getElementById("textarea3").value;
    var t4 = document.getElementById("textarea4").value;

    var result = JSON.parse(bridge.doIt(t1,t2,t3,t4));
    }
}

在应用程序的web视图:

In the application's webview:

  class MyBridge {
        public MyBridge(Context context) {
            // ...
        }
        @JavascriptInterface
        public String doIt(String t1,
                String t2,
                String t3,
                String t4) {
        // do whatever you want here with the values
        }
    }

和在web视图的构造函数:

and in the webview's constructor:

    this.addJavascriptInterface(new MyBridge(pContext), "bridge");

这应该工作(使用它自己)。 如果你不希望使用一个OK按钮,你就必须改变codeA位,以满足您的需求,也许呼吁文本字段的onKey preSS的功能。

This should work (using it myself). If you don't want to use an OK button, you'll have to change the code a bit to fit your needs, maybe call a function on the "onKeyPress" of the text fields.