JQuery UI Accordion 使用问题

发布于 2024-12-03 16:12:48 字数 776 浏览 0 评论 0原文

我正在尝试使用 JQuery Accordion,但是我在编写代码时遇到了困难。

 <div id="accordion">
    <h3><a href="#" id="first">First header</a></h3>
    <div id="first_content">First content</div>
    <h3><a href="#" id="second">Second header</a></h3>
    <div id="second_content">Second content</div>
</div>

我想在用户单击标题时更改第一个标题下方的 div 内容,但是我无法理解应该如何编写绑定函数以及手风琴函数中还需要提及的内容

$( "#accordion" ).accordion({
   change: function(event, ui) { what to write in here }
});

$( "#accordion" ).bind( "accordionchange", function(event, ui) {
  what to write in here
});

假设 HTML 内容是替换为存在于

var html = '<h1>Accordion Usage</h1>';

I am trying to use JQuery Accordion, however I am facing a difficulty in writing the code.

 <div id="accordion">
    <h3><a href="#" id="first">First header</a></h3>
    <div id="first_content">First content</div>
    <h3><a href="#" id="second">Second header</a></h3>
    <div id="second_content">Second content</div>
</div>

I want to change the content of the div below the first heading when the user clicks the heading, however I am not able to understand that how I should write the binding function and what else to mention in the accordion function

$( "#accordion" ).accordion({
   change: function(event, ui) { what to write in here }
});

$( "#accordion" ).bind( "accordionchange", function(event, ui) {
  what to write in here
});

Supposing the HTML content to be replaced with is present in

var html = '<h1>Accordion Usage</h1>';

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

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

发布评论

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

评论(2

天气好吗我好吗 2024-12-10 16:12:48

文档 中:

$('.ui-accordion').bind('accordionchange', function(event, ui) {
  ui.newHeader // jQuery object, activated header
  ui.oldHeader // jQuery object, previous header
  ui.newContent // jQuery object, activated content
  ui.oldContent // jQuery object, previous content
});

因此您可以使用 jQuery 函数来替换元素内容:

$( "#accordion" ).bind( "accordionchange", function(event, ui) {
    ui.newHeader.html("<h1>Accordion Usage</h1>");
});

或者您可以提供初始化时的回调:

$( "#accordion" ).accordion({
    change: function(event, ui) { ui.newHeader.html("<h1>Accordion Usage</h1>"); }
});

From the documentation:

$('.ui-accordion').bind('accordionchange', function(event, ui) {
  ui.newHeader // jQuery object, activated header
  ui.oldHeader // jQuery object, previous header
  ui.newContent // jQuery object, activated content
  ui.oldContent // jQuery object, previous content
});

So you can use the jQuery functions to replace the element content:

$( "#accordion" ).bind( "accordionchange", function(event, ui) {
    ui.newHeader.html("<h1>Accordion Usage</h1>");
});

or you can supply the callback at initialization:

$( "#accordion" ).accordion({
    change: function(event, ui) { ui.newHeader.html("<h1>Accordion Usage</h1>"); }
});
夕色琉璃 2024-12-10 16:12:48
$('.ui-accordion').bind('accordionchange', function(event, ui) {
  $("<div/>", {html : "Hello World"}).appendTo(ui.newContent);
});
$('.ui-accordion').bind('accordionchange', function(event, ui) {
  $("<div/>", {html : "Hello World"}).appendTo(ui.newContent);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文