gpt4 book ai didi

HTMLPanel 中的 Javascript

转载 作者:搜寻专家 更新时间:2023-10-31 08:21:34 25 4
gpt4 key购买 nike

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

Scripts/pro.js

alert('hello');

WITH HTMLPANEL 不工作(不显示警报)

MyPage.java(它是 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>

没有 HTMLPANEL 也能工作(显示警告)

MyPage.html

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

最佳答案

我认为应该反过来。引用 javadoc 的 HTMLPanel

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

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

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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7057312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com