HTMLPanel中的Javascript [英] Javascript in HTMLPanel

查看:108
本文介绍了HTMLPanel中的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在HTMLPanel元素中包含Javascript代码,但它不起作用。你可以帮我吗?提前致谢。

脚本/ pro.js

 警报( '你好'); 

使用HTMLPANEL不起作用(不显示提醒)

MyPage.java(MyPoint.html的EntryPoint)

  String preHtml =< script type = \text / javascript\src = \Scripts / pro.js\>< / script> ; 
HTMLPanel prePanel = new HTMLPanel(preHtml);
RootPanel.get(scriptContainer)。add(prePanel);

MyPage.html

 < td align =leftvalign =topid =scriptContainer>< / td> 

无HTMLPANEL工作(显示警告)



MyPage.html

 < td align =leftvalign =top>< script type =text / javascriptsrc =Scripts / pro.js>< / script>< / td> 


解决方案

我认为应该采用其他方式。 HTMLPanel引用javadocs
$ b


一个包含HTML的面板,可以将子窗口小部件附加到该HTML中标识的
元素。

应该包装您的容器而不是您的脚本。除非你完全有理由使用HTMLPanel来包装脚本,否则下面的例子是有效的。

  HTMLPanel html = new HTMLPanel(< ; table>< tr>< td id ='scriptContainer>< / td>< / tr>< / table>); 
RootPanel.get()。add(html);
元素脚本= DOM.createElement(script);
DOM.setElementAttribute(script,language,JavaScript);
DOM.setElementAttribute(script,src,Scripts / pro.js);
DOM.appendChild(DOM.getElementById(scriptContainer),script);


I want to include Javascript code in a HTMLPanel element, but it is not working. Could you please help me? Thanks in advance.

Scripts/pro.js

alert('hello');

WITH HTMLPANEL DOES NOT WORK (no alert is displayed)

MyPage.java (which is EntryPoint for MyPage.html)

String preHtml="<script type=\"text/javascript\" src=\"Scripts/pro.js\"></script>";
HTMLPanel prePanel=new HTMLPanel(preHtml);
RootPanel.get("scriptContainer").add(prePanel);

MyPage.html

<td align="left" valign="top" id="scriptContainer"></td>

WITHOUT HTMLPANEL DOES WORK (alert is displayed)

MyPage.html

<td align="left" valign="top"><script type="text/javascript" src="Scripts/pro.js"></script></td>

解决方案

I think it should be other way around. The HTMLPanel quoting the javadocs

A panel that contains HTML, and which can attach child widgets to identified elements within that HTML.

should wrap your container not your script. The below example works unless you absolutely have a reason to use HTMLPanel to wrap a script.

HTMLPanel html = new HTMLPanel("<table><tr><td id='scriptContainer'></td></tr></table>");
RootPanel.get().add(html);  
Element script = DOM.createElement("script");
DOM.setElementAttribute(script,"language","JavaScript");
DOM.setElementAttribute(script,"src","Scripts/pro.js");
DOM.appendChild(DOM.getElementById("scriptContainer"),script);

这篇关于HTMLPanel中的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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