cms 使如何在我的模板中包含 javascript 变得简单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5675330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:59:45  来源:igfitidea点击:

cms made simple how to include javascript in my template

javascriptincludecmsmadesimple

提问by Umer Hassam

Hi I'm a bit stuck here, i cant seem to be able to include the javascript file in my cmsms template.

嗨,我有点卡在这里,我似乎无法在我的 cmsms 模板中包含 javascript 文件。

<script src="js/slides.min.jquery.js"></script>
<script>
    $(function(){
        $('#slides').slides({
            preload: true,
            preloadImage: 'img/loading.gif',
            play: 5000,
            pause: 2500,
            hoverPause: true
        });
    });
</script>

This code doesent work, it neither includes the js/slides.min.jquery.jsnor does it run the script,, can any one please explain how javascript is included in cmsms templates...

这段代码不起作用,它既不包含js/slides.min.jquery.js也不运行脚本,任何人都可以解释一下 javascript 是如何包含在 cmsms 模板中的...

回答by uvesten

You need to include the javascript in {literal}tags, to avoid cmsms trying to parse it. This is an example (from one of my sites), that includes the Google analytics javascript.

您需要在{literal}标签中包含 javascript ,以避免 cmsms 尝试解析它。这是一个示例(来自我的一个网站),其中包括 Google 分析 javascript。

{literal}
<script type="text/javascript">

 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
 _gaq.push(['_trackPageview']);

 (function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +     '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();

</script>
{/literal}