从 Java GWT 代码调用 .js 文件的 Javascript 函数 [英] Calling Javascript function of .js file from java GWT code

查看:21
本文介绍了从 Java GWT 代码调用 .js 文件的 Javascript 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Java GWT 代码中有一个按钮.我在脚本文件夹中有一个 javascript 文件.我想在单击按钮时访问该 js 文件的功能.

I have one button in Java GWT code. And I have one javascript file in scripts folder. I want to access functions of that js file on Button click.

那么如何从 Java GWT 代码(按钮的点击事件)调用该方法?

So how can I call that method from Java GWT code(Button's click event)..?

谁能告诉我访问js文件功能的代码或方法.

Can anyone please tell me code or way for accessing js file's function.

提前致谢.

推荐答案

由于您的代码不应依赖于 gwt 链接器(以及它如何加载代码),因此您需要使用正确的窗口对象作为调用的前缀.Reapp 没有考虑到这一点.所以它实际上需要是:

since your code should not depend on the gwt linker (and how it loads code) you need to prefix the call with the right window object. Reapp does not take that into account. So it actually needs to be:

public static native void onMyButtonClick() /*-{
    $wnd.myJSfunction();
}-*/;

这篇关于从 Java GWT 代码调用 .js 文件的 Javascript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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