gpt4 book ai didi

java - jQuery 和 Java 小程序

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:55:27 24 4
gpt4 key购买 nike

我正在做一个项目,我们使用 Java applet 作为 UI 的一部分(特别是 map ),但 UI 的其余部分使用 HTML/JavaScript 围绕 applet 构建,通过以下方式与 applet 通信实时连接/NPAPI。有点奇怪,我知道,但让我们假设设置不在讨论范围内。我开始计划使用 jQuery 作为我的 JavaScript 框架,但我遇到了两个问题。

发出第一个:

选择小程序不提供对小程序方法的访问。

Java:

public class MyApplet extends JApplet {
// ...
public String foo() { return "foo!"; }
}

JavaScript:

var applet = $("#applet-id");
alert(applet.foo());

运行上面的 JavaScript 结果是

$("#applet-id").foo is not a function

This is in contrast to Prototype, where the analogous code does work:

var applet = $("applet-id");
alert(applet.foo());

那么...applet 方法去哪儿了?

发出第二个:

Firefox 2 中的 jQuery 和小程序存在一个已知问题:http://www.pengoworks.com/workshop/jquery/bug_applet/jquery_applet_bug.htm

希望不大,但有人知道解决方法吗?我怀疑这个问题无法修复,这意味着要切换到 Prototype。

感谢您的帮助!

最佳答案

第一期,试试怎么样

alert( $("#applet-id")[0].foo() );

这里的第二期是 thread有可能的解决方法。

引用解决方法

// Prevent memory leaks in IE
// And prevent errors on refresh with events like mouseover in other browsers
// Window isn't included so as not to unbind existing unload events
jQuery(window).bind("unload",
function() {
jQuery("*").add(document).unbind();
});

将该代码更改为:

// Window isn't included so as not to unbind existing unload events
jQuery(window).bind("unload",
function() {
jQuery("*:not('applet, object')").add(document).unbind();
});

关于java - jQuery 和 Java 小程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com