Javascript 如何在JQuery显示/隐藏方法中停止重复div?

Javascript 如何在JQuery显示/隐藏方法中停止重复div?,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我的问题是,当我将我的ajax称为加载图像时,每次单击下一页时都会重复它,我需要停止此重复加载图像,并在单击下一页时显示一次 我所做的是制作,然后使用jqueryshow/hide方法显示div 我在我的html页面中有这个div <div class="image_ajax_loader" style="display:none;" > <p class="loadingimage"> <img src="{$img_ps_dir}load

我的问题是,当我将我的ajax称为加载图像时,每次单击下一页时都会重复它,我需要停止此重复加载图像,并在单击下一页时显示一次

我所做的是制作
,然后使用jqueryshow/hide方法显示div

我在我的
html
页面中有这个
div

<div class="image_ajax_loader" style="display:none;" >
    <p class="loadingimage">
        <img src="{$img_ps_dir}loader.gif" alt="" />
        <br />{l s='Loading...' mod='blocklayered'}
    </p>
</div>
我通过以下方式隐藏它:

$('.image_ajax_loader').hide();
这是我的JQuery代码:

function reloadContent(params_plus)
{
    stopAjaxQuery();

    if (!ajaxLoaderOn)
    {
        $('.image_ajax_loader').show();
        $('.product_list').hide();
        ajaxLoaderOn = 1;
    }

    data = $('#layered_form').serialize();
    $('.layered_slider').each( function () {
        var sliderStart = $(this).slider('values', 0);
        var sliderStop = $(this).slider('values', 1);
        if (typeof(sliderStart) == 'number' && typeof(sliderStop) == 'number')
            data += '&'+$(this).attr('id')+'='+sliderStart+'_'+sliderStop;
    });

    $(['price', 'weight']).each(function(it, sliderType)
    {
        if ($('#layered_'+sliderType+'_range_min').length)
            data += '&layered_'+sliderType+'_slider='+$('#layered_'+sliderType+'_range_min').val()+'_'+$('#layered_'+sliderType+'_range_max').val();
    });

    $('#layered_form .select option').each( function () {
        if($(this).attr('id') && $(this).parent().val() == $(this).val())
            data += '&'+$(this).attr('id') + '=' + $(this).val();
    });

    if ($('.selectProductSort').length && $('.selectProductSort').val())
    {
        if ($('.selectProductSort').val().search(/orderby=/) > 0)
        {
            // Old ordering working
            var splitData = [
                $('.selectProductSort').val().match(/orderby=(\w*)/)[1],
                $('.selectProductSort').val().match(/orderway=(\w*)/)[1]
            ];
        }
        else
        {
            // New working for default theme 1.4 and theme 1.5
            var splitData = $('.selectProductSort').val().split(':');
        }
        data += '&orderby='+splitData[0]+'&orderway='+splitData[1];
    }
    if ($('select[name=n]:first').length)
    {
        if (params_plus)
            data += '&n=' + $('select[name=n]:first').val();
        else
            data += '&n=' + $('div.pagination form.showall').find('input[name=n]').val();
    }

    var slideUp = true;
    if (params_plus == undefined || !(typeof params_plus == 'string'))
    {
        params_plus = '';
        slideUp = false;
    }

    // Get nb items per page
    var n = '';
    if (params_plus)
    {
        $('div.pagination select[name=n]').children().each(function(it, option) {
            if (option.selected)
                n = '&n=' + option.value;
        });
    }
    ajaxQuery = $.ajax(
    {
        type: 'GET',
        url: baseDir + 'modules/blocklayered/blocklayered-ajax.php',
        data: data+params_plus+n,
        dataType: 'json',
        cache: false, // @todo see a way to use cache and to add a timestamps parameter to refresh cache each 10 minutes for example
        success: function(result)
        {
            $('.image_ajax_loader').hide();

            if (result.meta_description != '')
                $('meta[name="description"]').attr('content', result.meta_description);

            if (result.meta_keywords != '')
                $('meta[name="keywords"]').attr('content', result.meta_keywords);

            if (result.meta_title != '')
                $('title').html(result.meta_title);

            if (result.heading != '')
                $('h1.page-heading .cat-name').html(result.heading);

            $('#layered_block_left').replaceWith(utf8_decode(result.filtersBlock));
            $('.category-product-count, .heading-counter').html(result.categoryCount);

            if (result.nbRenderedProducts == result.nbAskedProducts)
                $('div.clearfix.selector1').hide();

            if (result.productList){
                $('.product_list').replaceWith(utf8_decode(result.productList));
            }
            else
                $('.product_list').html('');

            $('.product_list').css('opacity', '1');
            if ($.browser.msie) // Fix bug with IE8 and aliasing
                $('.product_list').css('filter', '');

            if (result.pagination.search(/[^\s]/) >= 0)
            {
                var pagination = $('<div/>').html(result.pagination)
                var pagination_bottom = $('<div/>').html(result.pagination_bottom);

                if ($('<div/>').html(pagination).find('#pagination').length)
                {
                    $('#pagination').show();
                    $('#pagination').replaceWith(pagination.find('#pagination'));
                }
                else
                    $('#pagination').hide();

                if ($('<div/>').html(pagination_bottom).find('#pagination_bottom').length)
                {
                    $('#pagination_bottom').show();
                    $('#pagination_bottom').replaceWith(pagination_bottom.find('#pagination_bottom'));
                }
                else
                    $('#pagination_bottom').hide();
            }
            else
            {
                $('#pagination').hide();
                $('#pagination_bottom').hide();
            }

            paginationButton(result.nbRenderedProducts, result.nbAskedProducts);
            ajaxLoaderOn = 0;

            // On submiting nb items form, relaod with the good nb of items
            $('div.pagination form').on('submit', function(e)
            {
                e.preventDefault();
                val = $('div.pagination select[name=n]').val();

                $('div.pagination select[name=n]').children().each(function(it, option) {
                    if (option.value == val)
                        $(option).attr('selected', true);
                    else
                        $(option).removeAttr('selected');
                });

                // Reload products and pagination
                reloadContent();
            });
            if (typeof(ajaxCart) != "undefined")
                ajaxCart.overrideButtonsInThePage();

            if (typeof(reloadProductComparison) == 'function')
                reloadProductComparison();

            filters = result.filters;
            initFilters();
            initSliders();

            current_friendly_url = result.current_friendly_url;

            // Currente page url
            if (typeof(current_friendly_url) === 'undefined')
                current_friendly_url = '#';

            // Get all sliders value
            $(['price', 'weight']).each(function(it, sliderType)
            {
                if ($('#layered_'+sliderType+'_slider').length)
                {
                    // Check if slider is enable & if slider is used
                    if (typeof($('#layered_'+sliderType+'_slider').slider('values', 0)) != 'object')
                    {
                        if ($('#layered_'+sliderType+'_slider').slider('values', 0) != $('#layered_'+sliderType+'_slider').slider('option' , 'min')
                        || $('#layered_'+sliderType+'_slider').slider('values', 1) != $('#layered_'+sliderType+'_slider').slider('option' , 'max'))
                            current_friendly_url += '/'+blocklayeredSliderName[sliderType]+'-'+$('#layered_'+sliderType+'_slider').slider('values', 0)+'-'+$('#layered_'+sliderType+'_slider').slider('values', 1)
                    }
                }
                else if ($('#layered_'+sliderType+'_range_min').length)
                    current_friendly_url += '/'+blocklayeredSliderName[sliderType]+'-'+$('#layered_'+sliderType+'_range_min').val()+'-'+$('#layered_'+sliderType+'_range_max').val();
            });

            window.location.href = current_friendly_url;

            if (current_friendly_url != '#/show-all')
                $('div.clearfix.selector1').show();

            lockLocationChecking = true;

            if (slideUp)
                $.scrollTo('.product_list', 400);
            updateProductUrl();

            $('.hide-action').each(function() {
                hideFilterValueAction(this);
            });

            if (display instanceof Function) {
                var view = $.totalStorage('display');

                if (view && view != 'grid')
                    display(view);
            }
        }
    });
    ajaxQueries.push(ajaxQuery);
}
函数重载内容(params_plus)
{
stopAjaxQuery();
如果(!ajaxLoaderOn)
{
$('.image\u ajax\u loader').show();
$('.product_list').hide();
ajaxLoaderOn=1;
}
数据=$(“#分层形式”).serialize();
$('.layered_slider')。每个(函数(){
var sliderStart=$(this.slider('values',0);
var sliderStop=$(this).slider('values',1);
if(typeof(sliderStart)='number'&&typeof(sliderStop)='number')
data+='&'+$(this).attr('id')+'='+sliderStart+'+'+sliderStop;
});
$(['price','weight'])。每个(函数(it,sliderType)
{
if($('#分层'+sliderType+''范围'.min')长度)
数据+='&分层+滑块类型+'''+$('.'分层+滑块类型+''范围最小值').val()+'.+$('.'分层+滑块类型+''范围最大值').val();
});
$('#分层形式.选择选项')。每个(函数(){
if($(this.attr('id')&&&$(this.parent().val()==$(this.val())
数据+='&'+$(this.attr('id')+'='+$(this.val();
});
if($('.selectProductSort').length&$('.selectProductSort').val())
{
if($('.selectProductSort').val().search(/orderby=/)>0)
{
//旧订单工作
var splitData=[
$('.selectProductSort').val().match(/orderby=(\w*)/)[1],
$('.selectProductSort').val().match(/orderway=(\w*)/)[1]
];
}
其他的
{
//默认主题1.4和主题1.5的新工作
var splitData=$('.selectProductSort').val().split(':');
}
数据+='&orderby='+splitData[0]+'&orderway='+splitData[1];
}
if($('select[name=n]:first')。长度)
{
如果(参数加)
data+='&n='+$('select[name=n]:first').val();
其他的
data+='&n='+$('div.pagination form.showall').find('input[name=n]')).val();
}
var slideUp=true;
if(params_plus==未定义的| |!(params_plus的类型=='string'))
{
参数加上=“”;
slideUp=false;
}
//每页获取nb项目
var n='';
如果(参数加)
{
$('div.pagination select[name=n]').children().each(函数(它,选项){
如果(选择选项)
n='&n='+option.value;
});
}
ajaxQuery=$.ajax(
{
键入:“GET”,
url:baseDir+'modules/blocklayered/blocklayered ajax.php',
数据:数据+参数+n,
数据类型:“json”,
cache:false,//@todo查看使用cache和添加timestamps参数以每10分钟刷新一次cache的方法,例如
成功:功能(结果)
{
$('.image\u ajax\u loader').hide();
如果(result.meta_description!='')
$('meta[name=“description”]”)attr('content',result.meta_description);
如果(result.meta_关键字!='')
$('meta[name=“keywords”]”)attr('content',result.meta_关键字);
如果(result.meta_title!='')
$('title').html(result.meta_title);
如果(result.heading!='')
$('h1.page-heading.cat name').html(result.heading);
$('layered#block_left')。替换为(utf8_decode(result.filtersBlock));
$('.category产品计数,.heading counter').html(result.categoryCount);
if(result.nbRenderedProducts==result.nbAskedProducts)
$('div.clearfix.selector1').hide();
if(result.productList){
$('.product_list')。替换为(utf8_解码(result.productList));
}
其他的
$('.product_list').html('');
$('.product_list').css('opacity','1');
if($.browser.msie)//修复带有IE8和别名的错误
$('product_list').css('filter','');
if(result.pagination.search(/[^\s]/)>=0)
{
var pagination=$('').html(result.pagination)
var pagination_bottom=$('').html(result.pagination_bottom);
if($('').html(分页).find('#分页').length)
{
$(“#分页”).show();
$(“#分页”).replaceWith(pagination.find(“#分页”);
}
其他的
$(“#分页”).hide();
if($('').html(分页_-bottom).find('.#分页_-bottom').length)
{
$(“#分页_底部”).show();
$(“#pagination_-bottom”).replace为(pagination_-bottom.find(“#pagination_-bottom”);
}
其他的
$(“#分页_底部”).hide();
}
其他的
{
$(“#分页”).hide();
$(“#分页_底部”).hide();
}
分页按钮(result.nbRenderedProducts、result.nbAskedProducts);
ajaxLoaderOn=0;
//在提交nb项目表时,与项目的良好nb相关
$('div.pagination form')。关于('submit',函数(e)
{
e、 预防默认值();
val=$('div.pagination select[name=n]')。val();
$('div.pagination select[name=n]').children().each(函数(它,选项){
如果(option.value==val)
$(选项).attr('selected',true);
其他的
$(选项).removeAttr('selected');
});
//雷洛亚
function reloadContent(params_plus)
{
    stopAjaxQuery();

    if (!ajaxLoaderOn)
    {
        $('.image_ajax_loader').show();
        $('.product_list').hide();
        ajaxLoaderOn = 1;
    }

    data = $('#layered_form').serialize();
    $('.layered_slider').each( function () {
        var sliderStart = $(this).slider('values', 0);
        var sliderStop = $(this).slider('values', 1);
        if (typeof(sliderStart) == 'number' && typeof(sliderStop) == 'number')
            data += '&'+$(this).attr('id')+'='+sliderStart+'_'+sliderStop;
    });

    $(['price', 'weight']).each(function(it, sliderType)
    {
        if ($('#layered_'+sliderType+'_range_min').length)
            data += '&layered_'+sliderType+'_slider='+$('#layered_'+sliderType+'_range_min').val()+'_'+$('#layered_'+sliderType+'_range_max').val();
    });

    $('#layered_form .select option').each( function () {
        if($(this).attr('id') && $(this).parent().val() == $(this).val())
            data += '&'+$(this).attr('id') + '=' + $(this).val();
    });

    if ($('.selectProductSort').length && $('.selectProductSort').val())
    {
        if ($('.selectProductSort').val().search(/orderby=/) > 0)
        {
            // Old ordering working
            var splitData = [
                $('.selectProductSort').val().match(/orderby=(\w*)/)[1],
                $('.selectProductSort').val().match(/orderway=(\w*)/)[1]
            ];
        }
        else
        {
            // New working for default theme 1.4 and theme 1.5
            var splitData = $('.selectProductSort').val().split(':');
        }
        data += '&orderby='+splitData[0]+'&orderway='+splitData[1];
    }
    if ($('select[name=n]:first').length)
    {
        if (params_plus)
            data += '&n=' + $('select[name=n]:first').val();
        else
            data += '&n=' + $('div.pagination form.showall').find('input[name=n]').val();
    }

    var slideUp = true;
    if (params_plus == undefined || !(typeof params_plus == 'string'))
    {
        params_plus = '';
        slideUp = false;
    }

    // Get nb items per page
    var n = '';
    if (params_plus)
    {
        $('div.pagination select[name=n]').children().each(function(it, option) {
            if (option.selected)
                n = '&n=' + option.value;
        });
    }
    ajaxQuery = $.ajax(
    {
        type: 'GET',
        url: baseDir + 'modules/blocklayered/blocklayered-ajax.php',
        data: data+params_plus+n,
        dataType: 'json',
        cache: false, // @todo see a way to use cache and to add a timestamps parameter to refresh cache each 10 minutes for example
        success: function(result)
        {
            $('.image_ajax_loader').hide();

            if (result.meta_description != '')
                $('meta[name="description"]').attr('content', result.meta_description);

            if (result.meta_keywords != '')
                $('meta[name="keywords"]').attr('content', result.meta_keywords);

            if (result.meta_title != '')
                $('title').html(result.meta_title);

            if (result.heading != '')
                $('h1.page-heading .cat-name').html(result.heading);

            $('#layered_block_left').replaceWith(utf8_decode(result.filtersBlock));
            $('.category-product-count, .heading-counter').html(result.categoryCount);

            if (result.nbRenderedProducts == result.nbAskedProducts)
                $('div.clearfix.selector1').hide();

            if (result.productList){
                $('.product_list').replaceWith(utf8_decode(result.productList));
            }
            else
                $('.product_list').html('');

            $('.product_list').css('opacity', '1');
            if ($.browser.msie) // Fix bug with IE8 and aliasing
                $('.product_list').css('filter', '');

            if (result.pagination.search(/[^\s]/) >= 0)
            {
                var pagination = $('<div/>').html(result.pagination)
                var pagination_bottom = $('<div/>').html(result.pagination_bottom);

                if ($('<div/>').html(pagination).find('#pagination').length)
                {
                    $('#pagination').show();
                    $('#pagination').replaceWith(pagination.find('#pagination'));
                }
                else
                    $('#pagination').hide();

                if ($('<div/>').html(pagination_bottom).find('#pagination_bottom').length)
                {
                    $('#pagination_bottom').show();
                    $('#pagination_bottom').replaceWith(pagination_bottom.find('#pagination_bottom'));
                }
                else
                    $('#pagination_bottom').hide();
            }
            else
            {
                $('#pagination').hide();
                $('#pagination_bottom').hide();
            }

            paginationButton(result.nbRenderedProducts, result.nbAskedProducts);
            ajaxLoaderOn = 0;

            // On submiting nb items form, relaod with the good nb of items
            $('div.pagination form').on('submit', function(e)
            {
                e.preventDefault();
                val = $('div.pagination select[name=n]').val();

                $('div.pagination select[name=n]').children().each(function(it, option) {
                    if (option.value == val)
                        $(option).attr('selected', true);
                    else
                        $(option).removeAttr('selected');
                });

                // Reload products and pagination
                reloadContent();
            });
            if (typeof(ajaxCart) != "undefined")
                ajaxCart.overrideButtonsInThePage();

            if (typeof(reloadProductComparison) == 'function')
                reloadProductComparison();

            filters = result.filters;
            initFilters();
            initSliders();

            current_friendly_url = result.current_friendly_url;

            // Currente page url
            if (typeof(current_friendly_url) === 'undefined')
                current_friendly_url = '#';

            // Get all sliders value
            $(['price', 'weight']).each(function(it, sliderType)
            {
                if ($('#layered_'+sliderType+'_slider').length)
                {
                    // Check if slider is enable & if slider is used
                    if (typeof($('#layered_'+sliderType+'_slider').slider('values', 0)) != 'object')
                    {
                        if ($('#layered_'+sliderType+'_slider').slider('values', 0) != $('#layered_'+sliderType+'_slider').slider('option' , 'min')
                        || $('#layered_'+sliderType+'_slider').slider('values', 1) != $('#layered_'+sliderType+'_slider').slider('option' , 'max'))
                            current_friendly_url += '/'+blocklayeredSliderName[sliderType]+'-'+$('#layered_'+sliderType+'_slider').slider('values', 0)+'-'+$('#layered_'+sliderType+'_slider').slider('values', 1)
                    }
                }
                else if ($('#layered_'+sliderType+'_range_min').length)
                    current_friendly_url += '/'+blocklayeredSliderName[sliderType]+'-'+$('#layered_'+sliderType+'_range_min').val()+'-'+$('#layered_'+sliderType+'_range_max').val();
            });

            window.location.href = current_friendly_url;

            if (current_friendly_url != '#/show-all')
                $('div.clearfix.selector1').show();

            lockLocationChecking = true;

            if (slideUp)
                $.scrollTo('.product_list', 400);
            updateProductUrl();

            $('.hide-action').each(function() {
                hideFilterValueAction(this);
            });

            if (display instanceof Function) {
                var view = $.totalStorage('display');

                if (view && view != 'grid')
                    display(view);
            }
        }
    });
    ajaxQueries.push(ajaxQuery);
}