【问题标题】:Add new scroll content (clone) to jQuery UI slider?向 jQuery UI 滑块添加新的滚动内容(克隆)?
【发布时间】:2013-09-13 02:18:37
【问题描述】:

所以我在小提琴中有一个类似于以下内容的滑块,需要选择添加新内容(块或滚动内容项)。添加后,我将进行内联编辑以更改以下文本,但我希望在克隆块时,其中没有先前的数字或文本。提前致谢。 http://jsfiddle.net/4QEgr/1/

$(".addNew").on("click", function(event){
    //clone last block
    //add new block to slider div
});

我的内容项包含这个,我需要在克隆时清除标签。

<div class="scroll-content-item ui-widget-header folder1">
    <span class="glyphicon glyphicon-folder-close icon-set" title='Folder1'>
        <label class='folderLbl'>Folder1</label>
    </span>
</div>

【问题讨论】:

    标签: javascript jquery jquery-ui clone add


    【解决方案1】:

    就用这个吧:

    $(".addNew").on("click", function (e) {
        scrollContent.append(function(){
            return $(this).find('.ui-widget-header:last')
                          .clone()
                          .text(function(i, h){
                              return parseInt(h, 10)+1;
                          });
        });
    });
    

    单击.addNew 时,它会获取最后一个.ui-widget-header 块,克隆它,增加数字并将其附加到.scroll-content 容器div。

    它正在运行:http://jsfiddle.net/v3K3m/

    更新:

    如果您的示例 HTML 块是:

    <div class="scroll-content-item ui-widget-header folder1">
        <span class="glyphicon glyphicon-folder-close icon-set" title='Folder1'>
            <label class='folderLbl'>Folder1</label>
        </span> 
    </div>
    

    那么你可以使用:

    $(".addNew").on("click", function (e) {
          scrollContent.append(function () {
              return $(this).find('.ui-widget-header:last')
                  .clone()
                  .find('.folderLbl')
                  .html(function (i, h) {
                      return 'Folder' + (parseInt(h.match(/\d+$/), 10)+1);
                  }).parents('.ui-widget-header');
          });
      });
    

    它正在运行:http://jsfiddle.net/ybmYD/

    【讨论】:

    • 好的,所以我的每个块都包含显示为图像和标签的文本。
    • 我如何只清除那个标签,而不是块中的所有内容?
    • 另外,使用 $(".folderLbl").empty();清除所有标签。我只需要$这个。
    • 还有一件事。所以我将标签更改为文本输入以进行内联编辑。如何操作上面的代码以相应地重命名这些输入?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 2015-02-22
    • 2012-02-06
    相关资源
    最近更新 更多