HTML页代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title></title>
<script type="text/javascript">
调用JAVA类的方法
functionnext(){
vartextvalue =(document.getElementByIdx_x('num1').value);
window.ncp.clickOnAndroid_saveIdnumber(textvalue);
}
这个JS方案是专门给JAVA回传用的
function wave(value){
document.getElementByIdx_x("XX").value= value;
}
</script>
</head>
<body >
<table width="962" height="748" border="0"cellpadding="0" cellspacing="0"bordercolor="F2F2F2">
<tr>
<td>
<input type="text" id="num1" />
<input type="text" id="XX"/>
<input type="button"name="Submit1" value="" onclick="next();" class="BOTTOM" style="background-color:#000000;border-0px
"/>
</td>
</tr>
</table>
</body>
</html>
JAVA代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title></title>
<script type="text/javascript">
调用JAVA类的方法
functionnext(){
}
这个JS方案是专门给JAVA回传用的
function wave(value){
}
</script>
</head>
<body >
<table width="962" height="748" border="0"cellpadding="0" cellspacing="0"bordercolor="F2F2F2">
</table>
</body>
</html>
JAVA代码:
public class Test extends Activity { privateHandler mHandler = new Handler(); privateWebView mWebView; public voidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.registerforpassword); //将WebView实例化 mWebView = (WebView) this.findViewById(R.id.webView); //WebView打开权限 mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); mWebView.getSettings().setJavaScriptEnabled(true); //使得获取焦点以后可以使用软键盘 mWebView.requestFocusFromTouch(); //允许使用JAVASCRIPT脚本 mWebView.addJavascriptInterface(newDemoJavaScriptInterface(), "ncp"); mWebView.loadUrl("file:///android_asset/Test.html"); } finalclassDemoJavaScriptInterface { //按扭业务 public voidclickOnAndroid_saveIdnumber(final String value){ System.out.println("前台传来的值:"+ value); mHandler.post(new Runnable() { public void run() { // 此处调用 HTML 中的javaScript 函数 System.out.println("去调用WAVE"); //不传参数 // mWebView.loadUrl("javascript:wave()"); //传二个参数 //mWebView.loadUrl("javascript:wave('" + value + "','" + value +"')"); //传一个参数 mWebView.loadUrl("javascript:wave('" + value +"')"); } }); } } }