【问题标题】:Import javascript into html on play 2.0 framework在 play 2.0 框架上将 javascript 导入 html
【发布时间】:2012-06-20 21:16:33
【问题描述】:

我在播放框架上的 html 中包含本地 javascript 文件时遇到问题。路径是正确的,我什至尝试将 javascript 文件包含在同一目录中。但是,从 Web 导入(我正在使用的主要库)工作得很好。

@(execId: String)

<html>

<head>
<title>Timeline</title>

<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>



<script type="text/javascript"

src="http://code.jquery.com/jquery-latest.js"></script>

<script type = "text/javascript" src = "../../public/javascripts/profilesJS/stack.js">  </script>


</head>


<body>
<input id="profiles" type="button" value="Profiles" />
<script type="text/javascript">
        alert(tester());
    </script>

</body>


</html>

javascript 文件看起来像这样

function tester(){

return "test";

}

我得到的错误是:

tester is not defined

与警报一致

【问题讨论】:

  • 我们不知道您尝试了什么。展示一些样本,让我们帮助您。
  • 我在我的代码中添加了我得到的错误(用 firebug 测试)

标签: javascript playframework playframework-2.0


【解决方案1】:

根据assets documentation(和一般路由),您需要在模板中使用反向路由:

<script type="text/javascript" src='@routes.Assets.at("javascripts/profilesJS/stack.js")'></script>

它会为您的/public/javascripts/profilesJS/stack.js 文件构建正确的src 路径(默认路由配置为/assets/javascripts/profilesJS/stack.js

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-08
    • 2013-02-28
    • 2012-03-31
    • 2012-06-16
    • 1970-01-01
    • 2017-05-30
    • 2012-02-20
    • 1970-01-01
    相关资源
    最近更新 更多