如何防止onblur代码执行&禁用(停止表格正常提交)

时间:2016-07-10 09:14:48

标签: javascript jquery ajax

无法禁用onclick / onblur值Click to see the problem in image

  name="otp" id="otp" size="50" maxlength="6" value="" onblur="encrypt_otp($(this).val());" type="password"   

// HTML代码

    <script>
        function encrypt_otp(otp_var) {
        // Stop form from submitting normally             

        $.ajax({
            type: "POST",
            url: "json/encryptData",
            dataType: "json",
            data: {otp :otp_var},
            success: function (data) {                    
                $('#otp').val(data['encrypted_value']);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(xhr.status);
                console.log(xhr.responseText);
                console.log(thrownError);
            }
        })
                .done(function (data) {
                })
                .fail(function () {

                })
                .always(function () {
                });
    }
     </script>           

是否可以通过preventDefault(); / return值来解决; 或者我该如何解决这个问题..

1 个答案:

答案 0 :(得分:0)

尝试在输入字段中设置autocomplete="off"

description