我在这个jQuery链接中做错了什么?

What am I doing wrong in this jQuery link?

本文关键字:错了 什么 链接 jQuery      更新时间:2023-09-26

我是一个完全的jQuery新手,但是我想在我的HTML页面上运行一个简单的accordion()代码。

这是我使用的链接,我包含了压缩后的jQuery 2.1.0

<head>
    <link rel="stylesheet" type="text/css" href="stylesheetkomik2.css">
    <script src="jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="scriptkomik2.js"></script>
    <title>Komiktoneel</title>
</head>

我尝试accordion()的代码片段是一系列带有标签的标签,其中包含段落,如:

<div id="content">
<h3>This is the first heading</h3>
<div><p>First paragraph</p></div>
<h3>This is the second heading</h3>
<div><p>Second paragraph</p></div>
</div>

scriptkomik2.js只包含以下代码:

$(document).ready(function(){
     $("#content").accordion();
})

是我的代码有问题还是链接错误?谢谢你

你需要添加jQuery UI

Accordion是来自jQuery UI的小部件,该库工作在jQuery之上。所以你需要把这两个js都添加到你的项目中。

<script src="js/jquery.js"></script>
<script src="js/jquery.ui.js"></script>

jQueryUI缺失。您还必须为accordian widget添加jQueryUI。

<head>
    <link rel="stylesheet" type="text/css" href="stylesheetkomik2.css">
    <script src="jquery-2.1.0.min.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <script type="text/javascript" src="scriptkomik2.js"></script>
    <title>Komiktoneel</title>
</head>

。accordion不是一个有效的jQuery方法。我想你正在寻找jquery UI: https://jqueryui.com/accordion/

添加以下脚本标签。Accordion是jQuery UI的一部分

  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>