Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android应用程序中使用jqMath_Android_Webview_Jqmath - Fatal编程技术网

在Android应用程序中使用jqMath

在Android应用程序中使用jqMath,android,webview,jqmath,Android,Webview,Jqmath,我是Android编程的新手,我想让jqMath在WebView中显示一些数学公式 这是我的密码: WebView webView = (WebView)findViewById(R.id.webView1); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); String js = "<html><head>" + "&

我是Android编程的新手,我想让jqMath在WebView中显示一些数学公式

这是我的密码:

    WebView webView = (WebView)findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
String js = "<html><head>"
    + "<link rel='stylesheet' href='jqmath-0.4.0.css'>"
    + "<script src='jquery-1.4.3.min.js'></script>"
    + "<script src='jqmath-etc-0.4.0.min.js'></script>"
    + "</head><body>"
    + "<script>var s = '$ax^2+bx+c=0$ with $a≠0$';M.parseMath(s);document.write(s);</script></body>";
webView.loadData(js,  "text/html",  "UTF-8");
WebView-WebView=(WebView)findViewById(R.id.webView1);
WebSettings WebSettings=webView.getSettings();
setJavaScriptEnabled(true);
字符串js=“”
+ ""
+ ""
+ ""
+ ""
+“var s=”$ax^2+bx+c=0$和$a≠0$';M.parseMath;document.write;“;
loadData(js,“text/html”,“UTF-8”);
此代码有什么问题

更新 我的问题已经解决了,但我还将loadData函数更改为loadDataWithBaseURL
如果其他人也有同样的问题,我只提一下以供参考。

假设您将js lib放置在assets/js中,js lib在assets文件夹中的位置与您的src声明不匹配。

假设您将js lib放置在assets/js中,您需要正确指定css、js文件的路径,如下所示:

WebView webView = (WebView)findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
String path="file:///android_asset/";
String js = "<html><head>"
+ "<link rel='stylesheet' href='"+path+"jqmath-0.4.0.css'>"
+ "<script src='"+path+"jquery-1.4.3.min.js'></script>"
+ "<script src='"+path+"jqmath-etc-0.4.0.min.js'></script>"
+ "</head><body>"
+ "<script>var s = '$ax^2+bx+c=0$ with $a≠0$';M.parseMath(s);document.write(s);</script></body>";
webView.loadData(js,  "text/html",  "UTF-8");
WebView-WebView=(WebView)findViewById(R.id.webView1);
WebSettings WebSettings=webView.getSettings();
setJavaScriptEnabled(true);
字符串路径=”file:///android_asset/";
字符串js=“”
+ ""
+ ""
+ ""
+ ""
+“var s=”$ax^2+bx+c=0$和$a≠0$';M.parseMath;document.write;“;
loadData(js,“text/html”,“UTF-8”);

请注意,文件应位于assets文件夹中。

您需要为css、js文件正确指定路径,如下所示:

WebView webView = (WebView)findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
String path="file:///android_asset/";
String js = "<html><head>"
+ "<link rel='stylesheet' href='"+path+"jqmath-0.4.0.css'>"
+ "<script src='"+path+"jquery-1.4.3.min.js'></script>"
+ "<script src='"+path+"jqmath-etc-0.4.0.min.js'></script>"
+ "</head><body>"
+ "<script>var s = '$ax^2+bx+c=0$ with $a≠0$';M.parseMath(s);document.write(s);</script></body>";
webView.loadData(js,  "text/html",  "UTF-8");
WebView-WebView=(WebView)findViewById(R.id.webView1);
WebSettings WebSettings=webView.getSettings();
setJavaScriptEnabled(true);
字符串路径=”file:///android_asset/";
字符串js=“”
+ ""
+ ""
+ ""
+ ""
+“var s=”$ax^2+bx+c=0$和$a≠0$';M.parseMath;document.write;“;
loadData(js,“text/html”,“UTF-8”);

请注意,这些文件应该位于assets文件夹中。

在像前面所说的那样指定了路径之后,以下内容对我有效

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

而不是
webView.loadData
方法。

在像前面所说的那样指定路径后,下面的方法对我有效

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

而不是
webView.loadData
方法。

使用M.parseMath是不正确的,并且正在复制到其他stackoverflow页面/问题。M.parseMath()应该传递一个DOM节点,而不是字符串,并且只有在页面完全加载后(例如,由于用户交互)需要更改数学时才需要。这里的调用是不可操作的。对于任何复制此代码的人,请去掉标记、变量s、M.parseMath调用和document.write。将整行代码改为“+”$ax^2+bx+c=0$,并加上$a≠0$";另外,js变量实际上是html,而不是js。使用M.parseMath是不正确的,并且正在复制到其他stackoverflow页面/问题。M.parseMath()应该传递一个DOM节点,而不是字符串,并且只有在页面完全加载后(例如,由于用户交互)需要更改数学时才需要。这里的调用是不可操作的。对于任何复制此代码的人,请去掉标记、变量s、M.parseMath调用和document.write。将整行代码改为“+”$ax^2+bx+c=0$,并加上$a≠0$";另外,js变量实际上是html,而不是js。我也遇到了类似的问题。这条路不可能短。如果没有路径,其余的代码可以工作,但无法加载.js文件,也无法呈现公式。这条路不可能短。如果没有路径,其余代码可以工作,但无法加载.js文件,也无法呈现公式。