Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.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
Javascript Android使用java脚本在webview中突出显示文本_Javascript_Android_Webview - Fatal编程技术网

Javascript Android使用java脚本在webview中突出显示文本

Javascript Android使用java脚本在webview中突出显示文本,javascript,android,webview,Javascript,Android,Webview,我使用webview呈现html文件,并使用java脚本突出显示html中的(Hello)单词 public class MyActivity extends Activity{ WebView myWebView; TextView myResult; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState){ super.o

我使用webview呈现html文件,并使用java脚本突出显示html中的(Hello)单词

 public class MyActivity extends Activity{
WebView myWebView;
TextView myResult;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    myResult = (TextView)this.findViewById(R.id.myResult);

    myWebView = (WebView)this.findViewById(R.id.myWebView);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.loadUrl("file:///android_asset/index.html");
   String txt="Hello";
   myWebView.loadUrl("javascript:var text='"+ txt+ "';if (window.find) {document.designMode ='on';var sel = window.getSelection();sel.collapse(document.body, 0);while (window.find(text)) { document.execCommand('HiliteColor', false, 'red');sel.collapseToEnd();}document.designMode = 'off';} else if (document.body.createTextRange) { var textRange = document.body.createTextRange(); while (textRange.findText(text)) {textRange.execCommand('BackColor', false, 'red'); textRange.collapse(false);}}");
   myWebView.addJavascriptInterface(new JavaScriptHandler(this), "MyHandler"); 
  }  
这是我的html

  <html>
   <head>
   </head>
  <body>
<h1>Hello World</h1>
   </body>
   </html>

你好,世界
这段代码在调试模式下运行良好,我的意思是它已经突出显示(hello),但在运行模式下它没有显示为什么??????????? 我不知道在调试模式下运行良好而不是在运行模式下运行是什么意思