简体   繁体   English

jQuery附加说明

[英]jQuery append clarification

I am statically binding the accordion panel like this: 我像这样静态绑定手风琴面板:

<body>
  <ul class="accordion_menu">
    <li class="has_sub">
      <div class="arrow_trigger up_arrow down_arrow"></div>
      <span>Dropdown</span>
      <ul>
        <li><a href=''>Option 1</a></li>
        <li><a href=''>Option 2</a></li>
      </ul>
    </li>
  </ul>     
</body>

The requirement was to bind the accordion using JSON/XML. 要求是使用JSON / XML绑定手风琴。 The call to JSON Object/XML works fine, but when I append the static element using a jQuery accordion panel, it is not functional. 对JSON Object / XML的调用工作正常,但是当我使用jQuery手风琴面板附加静态元素时,它不起作用。

Partial code is given below: 下面给出了部分代码:

$('.accordion_menu').append(
   "<li class='has_sub'>"
   + "<div class='arrow_trigger up_arrow down_arrow'>"
   + "</div><span>**JSON DATA GOES HERE**</span>"
   + "<ul>"
   + "<li><a href=''>Option 1</a></li>"
   + "<li><a href=''>Option 2</a></li>"
   + "</ul>"
   + "</li>");

What is the issue with the .append() function? .append()函数有什么问题?

There is no issue with the .append() function, but since the elements it adds were not present at the time the accordion was instantiated, they don't receive any of the event handlers with which the other accordion elements have been decorated. .append()函数没有问题,但是由于在实例化手风琴时不存在添加的元素,因此它们不会收到装饰了其他手风琴元素的任何事件处理程序。 You'll want to either re-instantiate the accordion after the .append() call, or wait until after .append() to instantiate the accordion. 您可能需要在.append()调用之后重新实例化手风琴,或者等到.append()之后实例化手风琴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM