stop a form submit (jQuery)

2019-09-06 05:35发布

I'm trying to stop a submit form with Javascript/jQuery, with a:

$('form#checkRepair').submit(function() {
    return false;
});

this work in all browsers, but not in Internet Explorer (version 8). In Internet Explorer version 9, works.

does anyone know what the problem is?

I'm use a jQuery version 1.6.4.

$('form#checkRepair').submit(function() {
    var nrObra = $('#nrObra').val();
    var nrDocCliente = $('#nrDocCliente').val();

    if((nrObra == '' || nrObra == 'Número de Reparação') 
        && (nrDocCliente == '' || nrDocCliente  == 'Doc. Cliente')) {
        $('form#checkRepair .error').show();
        return false;
    }

    $('form#checkRepair .error').hide();

    var nrJoja = $('#nrLoja').val();

    $(this).hide();
    $('#loader').show();

    var url = "http://uri.com";

    $.get(url, function(data) {
        if(typeof data.error != 'undefined') {
            $('#status_repair_error div').html('<h1>Ocorreu um Erro</h1>' + data.error);
            $('#status_repair_error').css('display', 'block');
            $('#status_repair').hide();
        } else {            
            $('#status_repair #repair-number span').text(data.repair.SAT_OBRANR);
            $('#status_repair #repair-state span').text(data.repair.situacao);
            $('#status_repair #repair-reason span').text(data.repair.motivo);
            $('#status_repair #product-name span').text(data.repair.produto);
            $('#status_repair #product-model span').text(data.repair.modelo);
            $('#status_repair #product-mark span').text(data.repair.marca);
            $('#status_repair #product-nrSerie span').text(data.repair.NSerieE);
            $('#status_repair #date-repair span').text(data.repair.dt_Pronta);
            $('#status_repair #date-lifting span').text(data.repair.dt_Entrega);
            $('#status_repair #client-name span').text(data.repair.cliente.nome);

            $("#status_repair li").each(function(index) {
                var text = $(this).children("span").text();
                if(text == '')
                    $(this).hide();
            });

            $('#nrObra').val('');
            $('#nrDocCliente').val('');
            $('#nrLoja').val('');
        }

        $.colorbox({
            inline:true, innerWidth:"960px", open: true, href: "#status_repair_container",
            onClosed:function(){ 
                $('form#checkRepair').show();
                $('#loader').hide();
                $('#status_repair_error').hide();
                $('#status_repair').show();
            }
        });
    }, 'jsonp');
    return false;
});

标签: jquery forms
3条回答
我命由我不由天
2楼-- · 2019-09-06 05:55

Try this:

$("form#checkRepair").submit(function(event) {

/* stop form from submitting normally */
event.preventDefault();

});         
查看更多
何必那么认真
3楼-- · 2019-09-06 06:08

Have you tried using the preventDefault() method?

$('form#checkRepair').submit(function(e) {
    e.preventDefault();
});
查看更多
Juvenile、少年°
4楼-- · 2019-09-06 06:13

the problem was in webform libary

查看更多
登录 后发表回答