当我在GXT中集成Designer Work中的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中使用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');
}
}-*/;