简体   繁体   English

从.tpl链接到外部Javascript文件不起作用

[英]Linking to external Javascript-file from .tpl does not work

I have a script for a navigation menu which works properly in a combination of JS, CSS and html. 我有一个用于导航菜单的脚本,可以在JS,CSS和html的组合中正常工作。 But if I place the html-code into a .tpl-File which uses Smarty, it doesn't work anymore, obviously the links, which refer to the external JS-files, are simply ignored: 但是,如果我将html代码放入使用Smarty的.tpl文件中,它将无法再使用,显然,引用外部JS文件的链接将被忽略:

<script src="menu/js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="menu/js/jquery.menu.min.js" type="text/javascript"></script>

Am I missing something? 我想念什么吗?

If I place the JS-function straight into the .tpl, it works well, but the response time of the page is pretty slow then. 如果我将JS函数直接放在.tpl中,则效果很好,但是页面的响应时间却很慢。 I have a sense that is because of the big bunch of JS-code in my .tpl-file, or does it make no difference? 我的感觉是因为我的.tpl文件中包含大量的JS代码,还是没有区别?

Nonetheless, I think the links to external files should work somehow. 尽管如此,我认为到外部文件的链接应该以某种方式起作用。

There should be no problem with what you are doing here, but make sure that you refer to the correct placement of your JavaScript-file. 您在这里所做的一切应该没有问题,但是请确保您引用了正确的JavaScript文件位置。

For example if the script is placed in a folder inside your templates directory: 例如,如果脚本位于templates目录内的文件夹中:

<script type='text/javascript' src='/templates/jquery/dropdown.js'></script>

This indicates the following placement of the file: 这表示文件的以下放置:

[doc_root]/templates/jquery/

as you do not open with " / " in your include-code, the code implements that the position of the file is relative to the current position. 因为您没有在包含代码中以“ / ”打开,所以该代码实现了文件的位置相对于当前位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM