HTMLPanel 中的 JavaScript
我想在 HTMLPanel 元素中包含 Javascript 代码,但它不起作用。请你帮助我好吗?提前致谢。
Scripts/pro.js
alert('hello');
使用 HTMLPANEL 不起作用(不显示警报)
MyPage.java(这是 MyPage 的 EntryPoint。 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>
没有 HTMLPANEL 也能工作(显示警报)
MyPage.html
<td align="left" valign="top"><script type="text/javascript" src="Scripts/pro.js"></script></td>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为应该是相反的。 HTMLPanel 引用 javadocs
应该包装您的容器而不是您的脚本。除非您绝对有理由使用 HTMLPanel 来包装脚本,否则下面的示例有效。
I think it should be other way around. The HTMLPanel quoting the javadocs
should wrap your container not your script. The below example works unless you absolutely have a reason to use HTMLPanel to wrap a script.