删除非活动类项

时间:2012-04-09 17:35:29

标签: jquery ajax class pagination

我正在尝试通过上传图片并将其添加到容器中来创建pagination div,方法是使用新的id's创建新的class并将current作为{ {1}}为第一页。

如果我更改为新页面,我会将活动类删除到当前页面并将其添加到所选页面。

我想知道如何删除所有没有“当前”类的inactive页面

这是我的代码:

<script type="text/javascript">
var imagesPerPage = 4, pageNumber = 1;

function onAjaxSucceded(data) {
    var pagesContainer = $('#pagesContainer'),
        imagesInPage = 0,
        divPage = $("#p1");

    $.each(data.result, function(index, file) {
        if (imagesInPage >= imagesPerPage) {
            imagesInPage = 1;
            pageNumber += 1;
            divPage = $('<div/>', {id : "p" + pageNumber}).addClass('pagedemo').hide().appendTo(pagesContainer);
        } else {
            imagesInPage += 1;
        }
        var src = 'Uploads/' + file.name;
        $('<img>', {src: src, href: src, "class": 'LoadclickImage', align: 'left'}).appendTo(divPage);
    });

    $("#demo5").paginate({
        count: pageNumber,
        start: 1,
        display: Math.min(7, pageNumber),
        border: true,
        border_color: '#fff',
        text_color: '#fff',
        background_color: 'black',
        border_hover_color: '#ccc',
        text_hover_color: '#000',
        background_hover_color: '#fff',
        images: false,
        mouse: 'press',
        onChange: function(page) {
            $('#paginationdemo ._current').removeClass('_current').hide();
            $('#p' + page).addClass('_current').show();
        }
    });
}

var fakeAjaxData = {
    result: [
        {name: '../../../img/keys.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/logo.png'},
    ]
};

$(function() {
    onAjaxSucceded(fakeAjaxData);
});
</script>

这是我的demo

修改

而不是removing inactive类可以有人说我如何删除所有页面,如果我再次添加,我需要添加1st page.截至目前的图像如果我删除它从添加的最后一页添加的页面。

如果我的标签错误,请原谅。

1 个答案:

答案 0 :(得分:1)

这样的事情:

$("#pagesContainer > :not(._current)").remove()