Ajax jquery-ui 手风琴

发布于 2024-08-31 00:14:04 字数 737 浏览 4 评论 0原文

我通过以下方式初始化我的手风琴:

$(function() {
  $("#gallery_accordion").accordion({ event: false });
  $("#gallery_accordion").click(function(e) {
    var contentDiv = $(this).next("div");
    contentDiv.load($(this).find("a").attr("href"));
  }); 
});

内容在单击时加载,但手风琴是不可见的。 什么也没显示。非常感谢任何帮助。
谢谢。

更新:高度保持为“0”。有什么理由吗?

这是标记:

<div id="gallery_accordion">
    <h3><a href="javascript:getGallery('369');">My first gallery</a></h3>
    <div id="gallery369">
    </div>

    <h3><a href="javascript:getGallery('381');">The second gallery</a></h3>
    <div id="gallery381">
    </div>
</div>

I init my accordion in the following way:

$(function() {
  $("#gallery_accordion").accordion({ event: false });
  $("#gallery_accordion").click(function(e) {
    var contentDiv = $(this).next("div");
    contentDiv.load($(this).find("a").attr("href"));
  }); 
});

The content is loaded onclick but the accordion is invisible.
Nothing is shown. Any help highly appreciated.

Thanks.

Update: The height stays at '0'. Any reason for that?

Here is the markup:

<div id="gallery_accordion">
    <h3><a href="javascript:getGallery('369');">My first gallery</a></h3>
    <div id="gallery369">
    </div>

    <h3><a href="javascript:getGallery('381');">The second gallery</a></h3>
    <div id="gallery381">
    </div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒江雪… 2024-09-07 00:14:04

尝试将您的初始调用更改为:

$("#gallery_accordion").accordion({ header: "h3", event : false });

将 HTML 更改为:

<div id="gallery_accordion">
<div>
    <h3><a href="javascript:getGallery('369');">My first gallery</a></h3>
    <div id="gallery369">
    </div>
</div>
<div>
    <h3><a href="javascript:getGallery('381');">The second gallery</a></h3>
    <div id="gallery381">
    </div>
</div>
</div>

每个单元格都需要有自己的 div 标签,并且在初始调用中,您现在已将标头设置为 H3 标记。

希望这有帮助。

这是加载手风琴的示例文档:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>jQuery UI Example Page</title>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/start/jquery-ui.css" rel="Stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function(){
                // Accordion
                $("#gallery_accordion").accordion({ header: "h3"});
                $("#gallery_accordion a").click(function(evt) {
          var galleryId = $(this).attr('href').split('#')[1];
          var contentDiv = $('#' + 'gallery' + galleryId);
          if(contentDiv.html() == " ") {
            var galleryContent = getGallery(galleryId);
            contentDiv.html(galleryContent);
          }
        });
                var galleryIdI = $('#gallery_accordion div div:first').attr('href').split('#')[1];
        var contentDivI = $('#' + 'gallery' + galleryId);
                var galleryContentI = getGallery(galleryId);
                contentDivI.html(galleryContentI);
            });
        </script>
    </head>
    <body>
    <!-- Accordion -->
        <h2 class="demoHeaders">Accordion</h2>
        <div id="gallery_accordion">
            <div>
                <h3><a href="#369">Gallery 1</a></h3>
                <div id="gallery369"> </div>
            </div>
            <div>
                <h3><a href="#381">Gallery 2</a></h3>
                <div id="gallery381"> </div>
            </div>
            <div>
                <h3><a href="#392">Gallery 3</a></h3>
                <div id="gallery392"> </div>
            </div>
        </div>
</body>
</html>

Try changing your initial call to:

$("#gallery_accordion").accordion({ header: "h3", event : false });

And your HTML to:

<div id="gallery_accordion">
<div>
    <h3><a href="javascript:getGallery('369');">My first gallery</a></h3>
    <div id="gallery369">
    </div>
</div>
<div>
    <h3><a href="javascript:getGallery('381');">The second gallery</a></h3>
    <div id="gallery381">
    </div>
</div>
</div>

Each of your cells needs to have its own div tag and in the initial call you have now set the header to the H3 tag.

Hope this helps.

Here is a sample doc that loads the accordion:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>jQuery UI Example Page</title>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/start/jquery-ui.css" rel="Stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function(){
                // Accordion
                $("#gallery_accordion").accordion({ header: "h3"});
                $("#gallery_accordion a").click(function(evt) {
          var galleryId = $(this).attr('href').split('#')[1];
          var contentDiv = $('#' + 'gallery' + galleryId);
          if(contentDiv.html() == " ") {
            var galleryContent = getGallery(galleryId);
            contentDiv.html(galleryContent);
          }
        });
                var galleryIdI = $('#gallery_accordion div div:first').attr('href').split('#')[1];
        var contentDivI = $('#' + 'gallery' + galleryId);
                var galleryContentI = getGallery(galleryId);
                contentDivI.html(galleryContentI);
            });
        </script>
    </head>
    <body>
    <!-- Accordion -->
        <h2 class="demoHeaders">Accordion</h2>
        <div id="gallery_accordion">
            <div>
                <h3><a href="#369">Gallery 1</a></h3>
                <div id="gallery369"> </div>
            </div>
            <div>
                <h3><a href="#381">Gallery 2</a></h3>
                <div id="gallery381"> </div>
            </div>
            <div>
                <h3><a href="#392">Gallery 3</a></h3>
                <div id="gallery392"> </div>
            </div>
        </div>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文