天天看點

android webview 調用js方法不起作用 jquery,android – JQuery在WebView上不起作用

我試圖将JQuery檔案包含在資源/腳本和Internet中,但不會顯示警報對話框。我得到了日志輸出并使其成為output.html,它在Windows中工作(很奇怪!)。

WebView有什麼問題?

public void onCreate(final Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

webView = (WebView) findViewById(R.id.webView);

final String s = "

" +

"" +

"" +

"" +

"

"$(document).ready(function(){ alert('hello'); });" +

"" +

"

All I hear is raindrops." +

"Falling on the rooftop. Oh baby tell me why you have to go. " +

"Cause this pain I feel you won't go away. And today, " +

"I'm officially missing you.

";

webView.getSettings().setJavaScriptEnabled(true);

Log.d("Something", s);

webView.loadDataWithBaseURL("file:///android_asset/", s, "text/html", "utf-8", null);

}

這是添加擴充名“.html”後的日志輸出。它适用于Firefox,但不适用于WebView。 🙁

All I hear is raindrops.Falling on the rooftop. Oh baby tell me why you have to go. Cause this pain I feel you won't go away. And today, I'm officially missing you.