为什么这个js手风琴不起作用?

时间:2014-02-27 04:46:06

标签: jquery accordion

I'm trying to get Jquery accordion working but I can't seem to.

Here is the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>accordion demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
    <div id="accordion">
         <h3>Read More</h3>

        <div>
            <p>Whether you choose to create a healthier lifestyle, deeper relationships, or seek more fulfillment in your career, TeamUp will take you there.</p>
            <p>You’ll discover your <b>patterns of behavior</b> and consciously choose which ones to keep and which ones to change. You'll experience your life from a new and refreshing perspective.</p>
        </div>
    </div>

<script>
$( "#accordion" ).accordion();
</script>
</body>

以下是我在JSFiddle上所做的事情

http://jsfiddle.net/CQu35/

任何帮助表示赞赏

由于

3 个答案:

答案 0 :(得分:1)

我能看到的唯一问题是使用相对协议,如果文件是从本地文件系统加载的话,它将无效

  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

你的jsfiddle有问题因为看起来jsfiddle不包含jQuery-ui.js文件

答案 1 :(得分:0)

看起来问题只与你的小提琴有关。我将你的整个代码粘贴在jsfiddle中,看起来它正在工作。

Same code pasted in your question

http://jsfiddle.net/sajith/VQ6z2/

答案 2 :(得分:0)

如果您:

,它可以正常工作
  • 使用jQuery 2.02
  • 使用JQuery UI 1.10.3
  • 在手风琴参数中设置collapsible: true(默认情况下,手风琴始终保持一个部分打开)

    $(“#accordion”)。accordion({   可折叠:是的 });