获取Android中的html文本区域的值 [英] Getting values of textarea of html in Android

查看:210
本文介绍了获取Android中的html文本区域的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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.

这篇关于获取Android中的html文本区域的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆