Body 标签中的 Wicket 1.5 Javascript 文件 [英] Wicket 1.5 Javascript File in Body Tag

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

问题描述

我需要在正文中放置一个脚本标签,因为 javascript 在 head 标签中不起作用.

I need to put a script-tag inside the body, because the javascript doesn't work in the head tag.

从 Wicket 1.5 开始,不再支持以下代码:

As of Wicket 1.5 the following code is not longer supported:

add(new JavaScriptReference("wz_tooltip", new JavaScriptResourceReference(BaseTemplate.class, "wz_tooltip.js")));

这是因为 JavaScriptReference 类不再存在.

This is because the class JavaScriptReference no longer exists.

我显然不能使用新的 renderHead 方法.

I can't obviously use the new renderHead method.

我目前的解决方法:

WebMarkupContainer script = new WebMarkupContainer("script");
script.add(new AttributeAppender("type", Model.of("text/javascript")));
script.add(new AttributeAppender("src", Model.of("wz_tooltip.js")));
add(script);

除了它不起作用之外真的很丑;找不到 javascript 文件.

Really ugly apart from that it doesn't work; can't find the javascript files.

是否有其他解决方法或正确"的方法来做到这一点?

Is there any other workaround or a "right" way to do it?

推荐答案

您是否尝试过将 urlFor 与资源引用一起使用?有点像..

Have you tried using a urlFor with a resource reference? Something like..

script.add(new AttributeAppender("src", urlFor(new JavaScriptResourceReference(BaseTemplate.class, "wz_tooltip.js"), null).toString())); 

由于 Wicket 的复杂资源管理,我不希望您当前的方法开箱即用.此外,虽然可能有其他正确"的方法来做事,但我经常发现 3rd-Party javascript 可能对放置很挑剔,我仍然需要为某些脚本使用这种方法.

I wouldn't expect your current method to work out of the box because of Wicket's complex resource management. Also, while there may be other "right" ways to do things, I've often found that 3rd-Party javascript can be finicky about placement and I still need to fall back on this method for some scripts.

例如,我使用的一个脚本必须是页面上的最后一个元素.

For example, one script I use must be the last element on the page.

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

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