jquery-ui - 我如何激活我的 jquery 手风琴,它不工作?
问题描述
这是我的代码,我正在处理 jquery 的本地文件。我一直在尝试向该代码添加手风琴,但它没有响应。我试图发出警报以查看我的 JavaScript 是否正在运行,并且我看到它正在响应,我不知道我的代码有什么问题。
<div id="accordion">
<h3><a href="#">Web development journey</a></h3>
<div>
<p>This how i ended up into the programming field...</p>
</div>
<h3><a href="#">Early Childhood and Education</a></h3>
<div>
<p>I waas born somewhere in the year 1999. I was born in a small village called Masuka village in Gokwe town, Midlands province, Zimbabwe.I am the first and lastborn...</p>
</div>
<h3><a href="#">Secondary and Tertiary education</a></h3>
<div>
<p>In my grade 7, I managed to score enough marks.....
</p>
</div>
</div>
<script>
$(document).on('ready', function() {
$("#accordion").accordion();
});
</script>
解决方案
使用 jQuery UI 示例:https ://jqueryui.com/accordion/我从您的代码中创建了以下内容。
$(function() {
$("#accordion").accordion();
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="accordion">
<h3><a href="#">Web development journey</a></h3>
<div>
<p>This how i ended up into the programming field...</p>
</div>
<h3><a href="#">Early Childhood and Education</a></h3>
<div>
<p>I waas born somewhere in the year 1999. I was born in a small village called Masuka village in Gokwe town, Midlands province, Zimbabwe.I am the first and lastborn...</p>
</div>
<h3><a href="#">Secondary and Tertiary education</a></h3>
<div>
<p>In my grade 7, I managed to score enough marks.....
</p>
</div>
</div>
这按预期工作。请检查您的代码以获取正确的语法。