javascript - Android WebView getElementById ('math')不能动态工作

标签 javascript android webview innerhtml mathjax

我有一个 WebView因为我已经加载了MathJax.js使用以下代码。

webView.loadDataWithBaseURL("","<script type='text/javascript' "
                  + "src="+ url +"></script>"
                  + "<span id='math'></span>"
                  /** 
                    I want set text dynamically for above span tag
                    using following script.
                   **/
                  + "<script type='text/javascript'>"
                  + "document.getElementById(\"math\").innerHTML='\\\\["+doubleEscapeTeX(question.getQuestion())+"\\\\]';"
                  + "</script>","text/html","utf-8","");

我想为上面的 <span> 动态设置文本使用以下标签 <script> .

<script type='text/javascript'>
   document.getElementById(\"math\").innerHTML='\\\\"+doubleEscapeTeX(question.getQuestion())+"\\\\]';"
</script>

如何使用 WebView 重新设置? ?

In short, i want to load javascript only once and other content load dynamically every time.

我们将不胜感激。

最佳答案

尝试使用

"$(function() { ... });" 

 "$(document).ready(function() { ... });".

<script type='text/javascript'>
   $(document).ready(function() {
    document.getElementById(\"math\").innerHTML='\\\\"+doubleEscapeTeX(question.getQuestion())+"\\\\]';"
   });
</script>

关于javascript - Android WebView getElementById ('math')不能动态工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25306250/

相关文章:

javascript - 使用 Greasemonkey 提交表单

android - 具有两个工作 Activity 的单个按钮

android - 为什么 API 22 坚持附加到 JDK 1.6?

java - 停止 Android 后退按钮重新启动 Activity

android - 当 Android 中的一个 fragment 有 WebView 时,如何将 Activity 划分在两个相同的 fragment 上?

javascript - href() 和 click() 不能很好地配合使用

javascript - Viewport - 用于在视口(viewport)中查找元素的 jQuery 选择器

javascript - React/Redux 变量在生产中返回 HTML

java - 无法将数据显示为来自 Firebase 的 ListView

javascript - 在 WebView 中通过 js 注入(inject)设置 TextBox 值