【问题标题】:GWT & GXT Problesm with javascript inside Html fragmentHtml 片段中的 javascript 的 GWT 和 GXT 问题
【发布时间】:2012-11-09 12:33:25
【问题描述】:

当我在 Gxt 中集成设计师工作的 Html 代码时遇到一些问题,我决定运行非常简单的测试并从使用 Gwt HtmlPanel 开始,我无法解释为什么不呈现包含的 javascript。

public class TestHTML implements EntryPoint {

    public void onModuleLoad() {

        String contenu = "<html>"
         +"<head>"
        +" <script type='text/javascript'>"
        +"function functionOne() { alert('You clicked the top text'); }"
        +"function functionTwo() { alert('You clicked the bottom text'); }"
        +"</script>"
        +"</head>"
        +"<body>"
         +"<p><a href='#' onClick='functionOne();'>Top Text</a></p>"
         +"<p><a href='javascript:functionTwo();'>Bottom Text</a></p>"
         +"</body>"
        +"</html>";
          HTMLPanel htmlPanel = new HTMLPanel(contenu);
          ContentPanel content = new ContentPanel();
          content.add(htmlPanel);
          RootPanel.get().add(content);

    }
} 

我在浏览器中找不到javascript函数(我用firebug查看) 有人有答案或建议吗? 问候

【问题讨论】:

    标签: gwt gxt


    【解决方案1】:

    你应该在gwt中使用JSNI。

    public void onModuleLoad() {
        registerJS();
        String contenu = "<html>"
                +"<body>"
                 +"<p><a href='#' onClick='functionOne();'>Top Text</a></p>"
                 +"<p><a href='javascript:functionTwo();'>Bottom Text</a></p>"
                 +"</body>"
                +"</html>";
                  HTMLPanel htmlPanel = new HTMLPanel(contenu);
                  RootPanel.get().add(htmlPanel);
    }
    
    public native void registerJS()/*-{
        $wnd.functionOne = function(){
            alert('you clicked the top text');
        }
    
        $wnd.functionTwo = function(){
            alert('you clicked the bottom text');
        }
    }-*/;
    

    【讨论】:

    • 非常感谢。由于我的问题最初更复杂,我必须从您的信息开始挖掘。有邮件联系方式吗?
    猜你喜欢
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多