开发者社区> 问答> 正文

freemarker如何优雅的在模版中将js放在页面最下面

用了macro后,没法将每个页面的js放在最下面

<!DOCTYPE html>
<#macro layout html_title>
    <html lang="zh-cn">
    <head>
        <title>${html_title}</title>
        <#include "/common/meta.html" />
        <#include "/common/css.html" />
    </head>
    <body>
    <#nested>
    <#include "/common/footer.html" />
    </body>
    <#include "/common/js.html" />
    </html>
</#macro>


其中
css.html是公共css

js.html是公共js,如jquery等

我没个页面使用这个layout的时候,所有的js都是在nested的位置的因此,使用jquery是失败的,应该把js代码放在include "/common/js.html"后面才对,因为js是顺序执行,请问有没有方法实现这个效果

我所有页面都是这么使用的

<#include "/common/layout.html" />
<@layout html_title="首页">
    <div id="aa">xxxxx</div>
<script>
    $("#aa").text("hello world");
</script>
</@layout>

那句js代码回失败,因为这时jquery还没引进来,请问如何处理

展开
收起
a123456678 2016-07-13 17:03:47 2785 0
1 条回答
写回答
取消 提交回答
  • screenshot

    2019-07-17 19:55:50
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
JavaScript函数 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载