【问题标题】:Why is jQuery Accordian making section the size of largest section even though autoHeight set to false为什么 jQuery Accordion 将部分设为最大部分的大小,即使 auto Height 设置为 false
【发布时间】:2013-09-02 08:13:31
【问题描述】:

即使 autoHeight 设置为 false,为什么 jQuery Accordian 仍将部分设置为最大部分的大小?

有两个部分,第一个部分仅包含少量文本,但展开后显示的大小与第二个部分相同。即使我已按照此问题accordion height issue 中的建议将 autoHeight 设置为 false

我是否以错误的方式或在错误的时间设置了此选项?

下面的完整源代码。

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/html" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="songkong.css">
 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#accordion" ).accordion({collapsible:true});
$( "#accordion" ).accordion({autoHeight:false});
});
</script></head>
<body>
<h2 class="ui-widget-header ui-corner-all">MusicBrainz Summary - Various Artists</h2>
<h2 class="warning ui-corner-all">Preview Only, no actual changes will be made to your music files</h2>
<div id="accordion">
<p>&emsp;25 Years of Rock 'n' Roll: 1964, Volume 2 - <a href="http://musicbrainz.org/release/8978a8ac-4337-4312-bcf2-58dc889ca6b4">8978a8ac-4337-4312-bcf2-58dc889ca6b4</a>, 1 songs of 20</br>&emsp;DE, Cat No:MRRT CD 64, CD</p>
<div><p><a href="http://musicbrainz.org/release/8978a8ac-4337-4312-bcf2-58dc889ca6b4">8978a8ac-4337-4312-bcf2-58dc889ca6b4</a></p>
<ul>
<li>Eden Kane - 01/14 - Boys Cry</li>
</ul>
</div>
<p>&emsp;Dedicated Follower of Fashion - <a href="http://musicbrainz.org/release/4c9b2f9d-2485-45f8-a370-06f60c420295">4c9b2f9d-2485-45f8-a370-06f60c420295</a>, 26 songs of 28</br>&emsp;GB, Castle Pulse, Cat No:PLS CD 138, CD</p>
<div><p><a href="http://musicbrainz.org/release/4c9b2f9d-2485-45f8-a370-06f60c420295">4c9b2f9d-2485-45f8-a370-06f60c420295</a></p>
<ul>
<li>The Moody Blues - 01/02 - Go Now</li>
<li>The Show Stoppers - 01/03 - Ain't Nothin' But A House Party</li>
<li>The Lemon Pipers - 01/04 - Green Tambourine</li>
<li>The Tremeloes - 01/05 - Here Comes My Baby</li>
<li>P.P. Arnold - 01/06 - The First Cut Is the Deepest</li>
<li>Dave Dee, Dozy, Beaky, Mick & Tich - 01/07 - Bend It</li>
<li>Petula Clark - 01/08 - Downtown</li>
<li>Gene Pitney - 01/09 - 24 Hours From Tulsa</li>
<li>The Foundations - 01/10 - Back On My Feet Again</li>
<li>Jimmy Justice - 01/11 - Spanish Harlem</li>
<li>The Overlanders - 01/12 - Michelle</li>
<li>The Kinks - 01/13 - Tired Of Waiting For You</li>
<li>Small Faces - 01/14 - The Universal</li>
<li>Petula Clark - 01/15 - I Couldn't Live Without Your Love</li>
<li>Gerry & The Pacemakers - 01/16 - Ferry 'Cross The Mersey</li>
<li>Dave Davis - 01/17 - Susannah's Still Alive</li>
<li>Long John Baldry - 01/18 - Let The Heartaches Begin</li>
<li>Jackie Trent - 01/19 - Where Are You Now My Love</li>
<li>Sandie Shaw - 01/20 - Message Understood</li>
<li>Joe Dolan - 01/21 - Make Me An Island</li>
<li>Gene Pitney - 01/23 - Somewhere In The Country</li>
<li>Dave Dee, Dozy, Beaky, Mick & Tich - 01/24 - Last Night In Soho</li>
<li>Sandie Shaw - 01/25 - I'll Stop At Nothing</li>
<li>Joe Brown - 01/26 - It Only Took A Minute</li>
<li>Kenny Ball & His Jazzmen - 01/27 - March Of The Siamese Children</li>
<li>Lonnie Donegan - 01/28 - The Party's Over</li>
</ul>
</div>
</div>
</body>
</html>

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    pablofiumara 打败了我,但少了几行尝试:

    $(function () {
        $("#accordion").accordion({
            collapsible: true,
            heightStyle: "content"
        });
    });
    

    【讨论】:

    • 谢谢,我确实尝试过首先使用 heightStyle,但使用了单独的行语法,所以也许这就是它不起作用的原因
    【解决方案2】:

    你的代码说:

    $(function() {
    $( "#accordion" ).accordion({collapsible:true});
    $( "#accordion" ).accordion({autoHeight:false});
    });
    

    我认为你应该这样编码:

    $(function() {
    $( "#accordion" ).accordion({
      collapsible: true
    });
    });
    
    $(function() {
    $( "#accordion" ).accordion({
      heightStyle: "content"
    });
    });
    

    【讨论】:

    • 您好,这不起作用。我对 Javascript 的了解有限,但似乎已经用相同的名称定义了两个函数,所以可能只有一个处于活动状态
    猜你喜欢
    • 2018-05-02
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多