【问题标题】:GWT inject jQuery script after page loadGWT 在页面加载后注入 jQuery 脚本
【发布时间】:2013-03-16 11:12:04
【问题描述】:

我有一个带有脚本文件 custom.js 的 html 页面,它是 GWT 的引导程序

<!DOCTYPE html>
<html>
<head>
    <!-- -->
    <script type="text/javascript" src="login/login.nocache.js"></script>
    <script type="text/javascript" src="common/js/custom.js"></script>
</head> 
        <div id="gwt-inject-place"/> 
</html>

没关系,一切正常。 但是在 custom.js 中,我需要在 login/login.nocache.js 在&lt;div id="gwt-inject-place"/&gt; 中注入一些 html 后触发功能。通常 custom.js 在注入之前以某种方式运行。

那么我应该怎么做才能注入 JavaScript jquery 文件呢?

alert('global');
jQuery(document).ready(function () 
{
 alert('inner');
}

这个注入 custom.js 但只有global alert 显示。

public void onModuleLoad(){
  RootPanel.get("gwt-inject-place").add(view);
  ScriptInjector.fromUrl("../common/js/custom.js").inject();
}

【问题讨论】:

    标签: gwt


    【解决方案1】:

    来自谷歌文档:

    <script src="js-url"/>
    

    自动注入位于 src 指定位置的外部 JavaScript 文件。有关详细信息,请参阅自动资源包含。

    所以,你必须在module.gwt.xml 上进行注入

    更多信息:Link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      • 2013-09-08
      • 1970-01-01
      相关资源
      最近更新 更多