netscape.javascript.JSException:SyntaxError:意外的关键字'this'。预期')'结束参数列表 [英] netscape.javascript.JSException: SyntaxError: Unexpected keyword 'this'. Expected ')' to end a argument list

查看:558
本文介绍了netscape.javascript.JSException:SyntaxError:意外的关键字'this'。预期')'结束参数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在HTML文档中插入一串文字到< h3 class =panel-title>< / h3> 元素中在WebView中。

I'm trying to insert a String of text into a <h3 class="panel-title"></h3> element inside a HTML document inside a WebView.

.java

.java

webEngine = webView.getEngine();

String headerText = "This is the Header";
webEngine.executeScript("testCheckMate(" + headerText + ");");

HTML

<h3 class="panel-title"></h3>

<script>
    $(document).ready(function() {
        window.testCheckMate = function (data) {
            $( ".panel-title" ).append( data );
        };
    });
</script>

但是,我仍然收到错误:

I, however, keep getting the error:

Caused by: netscape.javascript.JSException: SyntaxError: Unexpected keyword 'this'. Expected ')' to end a argument list.
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:128)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at com.sun.webkit.WebPage.executeScript(WebPage.java:1439)
at javafx.scene.web.WebEngine.executeScript(WebEngine.java:982)

我做错了什么?

推荐答案

您传递给Javascript的字符串方法需要引号:

The string you pass to the Javascript method needs to have quotes:

webEngine.executeScript("testCheckMate(\"" + headerText + "\");");

这篇关于netscape.javascript.JSException:SyntaxError:意外的关键字'this'。预期')'结束参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆