0

我以前发布过这个:关于使用 jquery 检查和取消选中多个元素时遇到问题的上一篇文章。

问题是我已经尝试了小提琴上的代码,并且感谢所有帮助我的人,它运行良好:我的小提琴,但它在我的网站上不起作用。

我有一个 base.php 可以自动加载核心插件、脚本等等......它甚至在调用:

<script src="{site_url()}assets/plugins/jquery-1.10.1.min.js" type="text/javascript"></script>

从视图文件中,我像这样调用我使用的 js 函数:(我使用 smarty 模板)

{block name='custom_javascript'}
<script src="{site_url()}assets/scripts/backend/filter-options.js"></script> 
{/block}

问题是检查/取消检查功能不起作用。它仅在我(再次)像这样调用 jquery 库时才有效:

{block name='custom_javascript'}
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="{site_url()}assets/scripts/backend/filter-options.js"></script> 
{/block}

即使它有效,但样式并不相同,因为框和文本出现不对齐。

我是在图书馆做错了什么还是可能是什么问题?提前感谢。

4

1 回答 1

0

From your comments, the problem is that your scripts are getting loaded like this:

<!-- page -->
...template header (from base.php)


...your template code
<script src="...filter_options.js"></script> <-- coming from your template



...template footer (from base.php)
<script src="...jquery"></script> <-- coming from base.php

So from this you can see that jQuery does not get loaded until AFTER your script. The problem here is that your script (filter_options.js) depends on jQuery and requires it to be loaded before it can be used.

I would move the jQuery script to the head of your base.php. Ideally, you would move the jQuery script to the head, and leave all other scripts in the footer. This gives you the benefit of always knowing you have jQuery available for use, no matter where you place scripts in your template files.

于 2013-10-22T17:40:53.167 回答