jQuery手风琴()不起作用 [英] jQuery accordion() not working

查看:93
本文介绍了jQuery手风琴()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jQuery手风琴()没有处理我的HTML段落。我哪里出错?

My jQuery accordion() is not working on my HTML paragraphs. Where did I go wrong?

simple.html

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <div id="mainContent">
            <h1>This is an According Example</h1>           
        </div>
        <div id="accordion">
            <h3><a href="#">Heading for first sentence</a></h3>
            <div>
            <p>This is the first sentence.</p>
            </div>          
            <h3><a href="#">Heading for second sentence</a></h3>            
            <div>
            <p>This is the second sentence.</p>
            </div>
            <h3><a href="#">Heading for third sentence</a></h3>
            <div>
            <p>This is the third sentence.</p>
            </div>
        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
        <script src="myscript.js"></script>
    </body>
</html>

myscript.js

window.onload = function(){
    $("#accordion").accordion();
};


推荐答案

使用此...

<!DOCTYPE html>
<html>
    <head>
    <title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
    <script src="myscript.js"></script>
</head>
<body>
    <div id="mainContent">
        <h1>This is an According Example</h1>           
    </div>
    <div id="accordion">
        <h3><a href="#">Heading for first sentence</a></h3>
        <div>
        <p>This is the first sentence.</p>
        </div>          
        <h3><a href="#">Heading for second sentence</a></h3>            
        <div>
        <p>This is the second sentence.</p>
        </div>
        <h3><a href="#">Heading for third sentence</a></h3>
        <div>
        <p>This is the third sentence.</p>
        </div>
    </div>
</body>

并把它放在头脑中标签

<script>
    $(document).on('ready', function(){
        $("#accordion").accordion();
    });
</script>

看到这个 jsFiddle示例

这篇关于jQuery手风琴()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆