【问题标题】:How to append a div at the end of jquery template?如何在 jquery 模板的末尾附加一个 div?
【发布时间】:2011-12-14 15:26:32
【问题描述】:

我有一个渲染图片的 jquery 模板

<script id="PictureList" type="text/x-jquery-tmpl">

    <ul class="pictureList">

      <li id="AddPicture">
          //an input box with browse button and upload button
      </li>

    </ul>

</script>

即它从返回PictureIDPicturePath 的数据库中读取数据。因此,每当页面加载时,它都会读取数据并附加到 pictureList 类。一切正常,但问题是 AddPicture 框首先呈现,我希望它在最后呈现。

我试图将它附加到 DOM 的 Ready 事件及其工作中,但它会使页面抖动并且不能提供正确的可见性。那么任何人都可以帮助我如何解决这个问题并在列表的最后呈现AddPicture 按钮。

【问题讨论】:

  • 你能分享你调用jquery模板插件的代码吗,比如$('#TemplateID').tmpl(data).appendTo('#targetDiv')

标签: jquery asp.net-ajax jquery-templates


【解决方案1】:

你可以使用 prepend() 代替 append: http://api.jquery.com/prepend

除了将生成的内容放在元素的开头之外,它的工作方式与追加类似。

【讨论】:

    【解决方案2】:

    我用过这个

    $.tmpl( "Pics", ProfilePics ).insertBefore( $(".pictureList > #AddPicture"));
    

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 2018-12-17
      • 2022-08-12
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多