Accordion 脚本出现问题,当我使用纯HTML处理 Accordion 时,该 Accordion 起作用了,但是现在移动到wordpress时, Accordion 已停止工作。

这是我的代码

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  <script>
  $(document).ready(function() {
    $("#accordion").accordion();
  });
  </script>
<?php wp_head(); ?>

和html:
            <div id="accordion">
 <div class="button"><a href="#">Infrastructure</a></div>
    <div><?php
            if (function_exists('iinclude_page')){
                iinclude_page('sectors/infrastructure');
            }?>
            </div>
    <div class="button"><a href="#">Housing</a></div>
    <div><?php
            if (function_exists('iinclude_page')){
                iinclude_page('sectors/housing');
            }?></div>
                <div class="button"><a href="#">Education</a></div>
    <div><?php
            if (function_exists('iinclude_page')){
                iinclude_page('sectors/education');
            }?></div>
                <div class="button"><a href="#">Health</a></div>
    <div><?php
            if (function_exists('iinclude_page')){
                iinclude_page('sectors/health');
            }?></div>
</div>

我真的不明白这个问题,因为它是直接在html中工作的。我什至尝试用纯文本删除include函数,但仍然无法正常工作?

有任何想法吗?也没有其他jquery对象相互干扰。

最佳答案

您要加载jQuery两次(先加载1.5,再加载1.7.1),然后在加载1.5之后但在加载1.7.1之前加载jQuery UI。所以这是发生了什么:

  • jQuery 1.5已加载。
  • jQuery UI已加载,并将其自身附加到该点上存在的jQuery对象。
  • 已加载jQuery 1.7.1,完全替代了jQuery对象。
  • 您的代码使用(1.7.1)jQuery对象运行,而jQuery UI尚未添加其优点。

  • 如果您仅加载一次jQuery,并确保随后加载jQuery UI,那么它将起作用。

    关于jquery - # Accordion 不是函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9017634/

    10-12 00:16
    查看更多