javascript - jQuery Accordion ()不工作

标签 javascript jquery html jquery-ui

我的 jQuery accordion() 无法处理我的 HTML 段落。我哪里出错了?

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>

把这个放在head标签里

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

看看这个 jsFiddle example

关于javascript - jQuery Accordion ()不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15776225/

相关文章:

Javascript - 获取未定义元素的宽度

javascript - onClick 事件返回代理对象而不是 ReactJX 中的事件处理程序对象

html - 使 div 小于其内容

javascript - WebAudio 振​​荡器 "click"

javascript - 使用 Dgrid 自定义排序

javascript - HTML contenteditable=true 乱序/意外改变表格行结构

javascript - 图表 : How to remove specific label

javascript - jquery页面刷新不管返回false

javascript - CKEDITOR 的 insertHtml 不工作,除了在 setTimeout 中

html - 我在网站上的百分比/布局问题。内容移动