保存信息后,使用jquery隐藏按钮

时间:2014-03-08 16:22:00

标签: javascript jquery html prestashop

我试图隐藏"保存"我的prestashop结帐页面中的按钮。默认情况下,当访客字段所有字段需要点击"保存"按钮。奇怪但按钮不会消失。可能是默认的东西js不行,但我不想触摸它。我想用小jquery隐藏这个按钮。

你可以看到它:test.detelinmarkov.com/quick-order 我尝试做什么: 当信息正确且已保存时,客户会看到消息"帐户信息已成功保存"我尝试这个消息显示"保存"按钮隐藏。

注意:在我尝试为成功保存的数据获取一些ID之前,因为如果客户返回到其他页面或刷新结账页面"帐户信息已成功保存"消失,按钮停留在那里。

我尝试的代码,但不起作用......

                {literal}
            <script>
            $('input[name=opc_account_saved]')
                .click(
                     function ()
                     {
                         $(this).hide();

                         $("savebutton").hide();
                     }
                );
            </script>
            {/literal}
            <div id="savebutton">
            <p class="submit">
                <input type="submit" class="exclusive button" name="submitAccount" id="submitAccount" value="{l s='Save'}" />
            </p>
            </div>
            <p style="display: none;" id="opc_account_saved">
                {l s='Account information saved successfully'}
            </p>

默认情况下,按钮没有消失的问题可能是这个js:

$(function() {
// GUEST CHECKOUT / NEW ACCOUNT MANAGEMENT
if ((!isLogged) || (isGuest))
{
    if (guestCheckoutEnabled && !isLogged)
    {
        $('#opc_account_choice').show();
        $('#opc_account_form, #opc_invoice_address').hide();

        $('#opc_createAccount').click(function() {
            $('.is_customer_param').show();
            $('#opc_account_form').slideDown('slow');
            $('#is_new_customer').val('1');
            $('#opc_account_choice, #opc_invoice_address').hide();
            updateState();
            updateNeedIDNumber();
            updateZipCode();
        });
        $('#opc_guestCheckout').click(function() {
            $('.is_customer_param').hide();
            $('#opc_account_form').slideDown('slow');
            $('#is_new_customer').val('0');
            $('#opc_account_choice, #opc_invoice_address').hide();
            $('#new_account_title').html(txtInstantCheckout);
            $('#submitAccount').prop({id : 'submitGuestAccount', name : 'submitGuestAccount'});
            updateState();
            updateNeedIDNumber();
            updateZipCode();
        });
    }
    else if (isGuest)
    {
        $('.is_customer_param').hide();
        $('#opc_account_form').show('slow');
        $('#is_new_customer').val('0');
        $('#opc_account_choice, #opc_invoice_address').hide();
        $('#new_account_title').html(txtInstantCheckout);
        updateState();
        updateNeedIDNumber();
        updateZipCode();
    }
    else
    {
        $('#opc_account_choice').hide();
        $('#is_new_customer').val('1');
        $('.is_customer_param, #opc_account_form').show();
        $('#opc_invoice_address').hide();
        updateState();
        updateNeedIDNumber();
        updateZipCode();
    }

    // LOGIN FORM
    $('#openLoginFormBlock').click(function() {
        $('#openNewAccountBlock').show();
        $(this).hide();
        $('#login_form_content').slideDown('slow');
        $('#new_account_form_content').slideUp('slow');
        return false;
    });
    // LOGIN FORM SENDING
    $('#SubmitLogin').click(function() {
        $.ajax({
            type: 'POST',
            headers: { "cache-control": "no-cache" },
            url: authenticationUrl + '?rand=' + new Date().getTime(),
            async: false,
            cache: false,
            dataType : "json",
            data: 'SubmitLogin=true&ajax=true&email='+encodeURIComponent($('#login_email').val())+'&passwd='+encodeURIComponent($('#login_passwd').val())+'&token=' + static_token ,
            success: function(jsonData)
            {
                if (jsonData.hasError)
                {
                    var errors = '<b>'+txtThereis+' '+jsonData.errors.length+' '+txtErrors+':</b><ol>';
                    for(var error in jsonData.errors)
                        //IE6 bug fix
                        if(error !== 'indexOf')
                            errors += '<li>'+jsonData.errors[error]+'</li>';
                    errors += '</ol>';
                    $('#opc_login_errors').html(errors).slideDown('slow');
                }
                else
                {
                    // update token
                    static_token = jsonData.token;
                    updateNewAccountToAddressBlock();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus !== 'abort')
                    alert("TECHNICAL ERROR: unable to send login informations \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
            }
        });
        return false;
    });

    // INVOICE ADDRESS
    $('#invoice_address').click(function() {
        bindCheckbox();
    });

    // VALIDATION / CREATION AJAX
    $('#submitAccount').click(function() {
        $('#opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow')

        var callingFile = '';
        var params = '';

        if (parseInt($('#opc_id_customer').val()) == 0)
        {
            callingFile = authenticationUrl;
            params = 'submitAccount=true&';
        }
        else
        {
            callingFile = orderOpcUrl;
            params = 'method=editCustomer&';
        }

        $('#opc_account_form input:visible, #opc_account_form input[type=hidden]').each(function() {
            if ($(this).is('input[type=checkbox]'))
            {
                if ($(this).is(':checked'))
                    params += encodeURIComponent($(this).attr('name'))+'=1&';
            }
            else if ($(this).is('input[type=radio]'))
            {
                if ($(this).is(':checked'))
                    params += encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val())+'&';
            }
            else
                params += encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val())+'&';
        });
        $('#opc_account_form select:visible').each(function() {
            params += encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val())+'&';
        });
        params += 'customer_lastname='+encodeURIComponent($('#customer_lastname').val())+'&';
        params += 'customer_firstname='+encodeURIComponent($('#customer_firstname').val())+'&';
        params += 'alias='+encodeURIComponent($('#alias').val())+'&';
        params += 'other='+encodeURIComponent($('#other').val())+'&';
        params += 'is_new_customer='+encodeURIComponent($('#is_new_customer').val())+'&';
        // Clean the last &
        params = params.substr(0, params.length-1);

        $.ajax({
            type: 'POST',
            headers: { "cache-control": "no-cache" },
            url: callingFile + '?rand=' + new Date().getTime(),
            async: false,
            cache: false,
            dataType : "json",
            data: 'ajax=true&'+params+'&token=' + static_token ,
            success: function(jsonData)
            {
                if (jsonData.hasError)
                {
                    var tmp = '';
                    var i = 0;
                    for(var error in jsonData.errors)
                        //IE6 bug fix
                        if(error !== 'indexOf')
                        {
                            i = i+1;
                            tmp += '<li>'+jsonData.errors[error]+'</li>';
                        }
                    tmp += '</ol>';
                    var errors = '<b>'+txtThereis+' '+i+' '+txtErrors+':</b><ol>'+tmp;
                    $('#opc_account_errors').slideUp('fast', function(){
                        $(this).html(errors).slideDown('slow', function(){
                            $.scrollTo('#opc_account_errors', 800);
                        });                         
                    }); 
                }
                else
                {
                    $('#opc_account_errors').slideUp('slow', function(){
                        $(this).html('');
                    });
                }

                isGuest = parseInt($('#is_new_customer').val()) == 1 ? 0 : 1;
                // update addresses id
                if(jsonData.id_address_delivery !== undefined && jsonData.id_address_delivery > 0)
                    $('#opc_id_address_delivery').val(jsonData.id_address_delivery);
                if(jsonData.id_address_invoice !== undefined && jsonData.id_address_invoice > 0)
                    $('#opc_id_address_invoice').val(jsonData.id_address_invoice);                  

                if (jsonData.id_customer !== undefined && jsonData.id_customer !== 0 && jsonData.isSaved)
                {
                    // update token
                    static_token = jsonData.token;

                    // It's not a new customer
                    if ($('#opc_id_customer').val() !== '0')
                        if (!saveAddress('delivery'))
                            return false;

                    // update id_customer
                    $('#opc_id_customer').val(jsonData.id_customer);

                    if ($('#invoice_address:checked').length !== 0)
                    {
                        if (!saveAddress('invoice'))
                            return false;
                    }

                    // update id_customer
                    $('#opc_id_customer').val(jsonData.id_customer);

                    // force to refresh carrier list
                    if (isGuest)
                    {
                        isLogged = 1;
                        $('#opc_account_saved').fadeIn('slow');
                        $('#submitAccount').hide();
                        updateAddressSelection();
                    }
                    else
                        updateNewAccountToAddressBlock();
                }
                $('#opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow');
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus !== 'abort')
                    alert("TECHNICAL ERROR: unable to save account \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
                $('#opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow')
            }
        });
        return false;
    });
}

bindCheckbox();
bindInputs();

$('#opc_account_form input,select,textarea').change(function() {
    if ($(this).is(':visible'))
    {
        $('#opc_account_saved').fadeOut('slow');
        $('#submitAccount').show();
    }
});

});

1 个答案:

答案 0 :(得分:2)

#选择器中缺少id

$("#savebutton").hide();
//-^-----