无法使用jquery禁用锚标签...在ajax调用()期间使用“disabled”和e.preventDefault()

时间:2015-09-02 05:48:34

标签: javascript jquery ajax

现在只有问题没有禁用锚标记我已经包含ajax提交库现在正在工作我只想在处理过程中解除锚点但是我不能禁用“禁用”和e.preventDefault()

感谢大家的帮助

        <?php } else if ($currStep == 1) { ?>
            <div class="row setup-content" id="step-2">
                <div class="col-xs-9 col-md-offset-1">   
                    <form id="form-change-password" class="form-horizontal" role="form" method="post" action="<?php echo base_url('user/save_password'); ?>">   
                        <div class="form-group">  
                            <label for="inputEmail" class="control-label col-md-3" style=" padding-left: 0px; ">New Password * </label>
                            <div class="col-md-9">
                                <input type="password" class="form-control input-sm password"  id="inputfield1" value="<?php echo set_value('password'); ?>" placeholder="New Password" name="password">
                                <span class="alert-danger"><?php echo form_error('password'); ?></span>
                            </div>
                        </div>
                        <div class="form-group">  
                            <label for="inputEmail" class="control-label col-md-3" style=" padding-left: 0px; ">Confirm Password * </label>
                            <div class="col-md-9">
                                <input type="password" class="form-control input-sm"  id="inputfield1" value="<?php echo set_value('cpassword'); ?>" placeholder="Confirm Password" name="cpassword">
                                <span class="alert-danger"><?php echo form_error('cpassword'); ?></span>
                            </div>
                        </div>
                        <div class="form-group ">  
                            <label for="inputfield2" class="col-sm-4 control-label"></label>
                            <div class="col-sm-8">
                                <a href="<?php echo base_url() . 'user/upate_step_status/2' ?>" class="nextBtn btn btn-primary pull-right "> Next </a>
                                <div class="loading-2 btn btn-default pull-right hidden" style="width: 70px">
                                    <img src="<?php echo base_url() . 'assets/frontend/img/loading-spinner-blue.gif'; ?>" alt="">
                                </div>
                                <button type="submit" class="save-2 submit btn btn-success pull-right">Save</button>
                                <a href="<?php echo base_url() . 'user/upate_step_status/0' ?>" class=" btn nextBtn btn-default pull-right"> Back </a>
                            </div>
                        </div>  
                    </form> 
                </div>
            </div>
        <?php } else if ($currStep == 2) { ?>

我将js更改为此

<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script> $('.loading-2').hide();</script>
<script>
    $(document).ready(function () {
        $('#form-change-password').validate({// initialize the plugin
            rules: {
                password: {
                    required: true,
                    minlength: 6
                },
                cpassword: {
                    equalTo: ".password"
                }
            },
            messages: {
                password: " Enter Password with 6 minimum characters",
                cpassword: "Password not matched"
            },
            submitHandler: function () {
                $("#form-change-password :input").prop("disabled", true);
                $("#form-change-password a").prop("disabled", true);
                $(".stepwizard-row a").prop("disabled", true);
                $(".loading-2").removeClass('hidden');
                $('.save-2, .loading-2').toggle();
                $('#form-change-password').ajaxSubmit({
                    success: function (result) {
                        console.log(result);
                        if (result == 1) {

                            setTimeout(function () {
                                $("#form-change-password :input").prop("disabled", false);
                                $("#form-change-password a").click(function (e) {
                                    console.log("oye sabar ker");
                                    e.preventDefault();
                                });
                                $(".stepwizard-row a").prop("disabled", false);
                                $('.save-2, .loading-2').toggle();
                            }, 10000);
                        } else {
                        }
                    }
                });
            },
        });
    });
</script>

4 个答案:

答案 0 :(得分:0)

看起来有一个逗号丢失。

请更改

                        cpassword :"Password not matched"
                },
        submitHandler: function() {

task xml_file_to_vs_build(type: Copy) {
   outputs.upToDateWhen { false }
   doLast {
      outputs.upToDateWhen { false }
      println("copying strings.xml");
      from 'src/main/res/values'
      into '../vso_build'
      include 'strings.xml'
   }
}

答案 1 :(得分:0)

在javascript中阻止消息后,您将丢失逗号。

我已经对代码上的缩进进行了标准化,因此更容易阅读。这也使得发现错误变得更加容易。

此外,你在冒号周围有不一致的空间,所以我也整理了它们。

编辑:jQuery匹配输入的id,而不是名称。

abs.a

答案 2 :(得分:0)

这不是你问的问题。但是,处理时禁用页面或部分的最佳方法是使用css添加覆盖元素,最好还使用加载图标。这样可以避免所有麻烦,并提供更好的演示。

答案 3 :(得分:0)

感谢所有我通过复制所有删除href attr然后再次添加href及其值在ajax调用后它适用于我,如果你有任何更好的主意请告诉我

<script> $('.loading-4').hide();</script>
<script>
    $(document).ready(function () {
        $('#form-update-profile').validate({// initialize the plugin
            rules: {
                title: {
                    required: true
                },
                department: {
                    required: true
                },
                description: {
                    required: true
                }
            },
            submitHandler: function () {
                $(".loading-4").removeClass('hidden');
                $('.save-4, .loading-4').toggle();
                $('.messages-success, .messages-danger').removeClass('hidden').addClass('hidden');
                $("#form-update-profile :input").prop("disabled", true);
                var nextHref = $("#form-update-profile .next").attr("href");
                var backHref = $("#form-update-profile .back").attr("href");
                var linkpage0 = $(".stepwizard-step .first").attr("href");
                var linkpage1 = $(".stepwizard-step .second").attr("href");
                var linkpage2 = $(".stepwizard-step .third").attr("href");
                var linkpage3 = $(".stepwizard-step .fourth").attr("href");
                var linkpage4 = $(".stepwizard-step .fifth").attr("href");
                $("#form-update-profile a").removeAttr("href");
                $(".stepwizard-step a").removeAttr("href");
                $('#form-update-profile').ajaxSubmit({
                    error: function () {
                        $('.messages-danger .alert-danger').text("Some Error Occurred, Please try again");
                        $('.messages-danger').removeClass('hidden');
                    },
                    success: function (response) {
                        response = $.parseJSON(response);
                        if (response['status'] == true) {
                            $('.messages-success .alert-success').text(response['message']);
                            $('.messages-success').removeClass('hidden');
                        } else {
                            $('.messages-danger .alert-danger').text(response['message']);
                            $('.messages-danger').removeClass('hidden');
                        }
                    },
                    complete: function () {
                        $("#form-update-profile .next").attr("href", nextHref);
                        $("#form-update-profile .back").attr("href", backHref);
                        $(".stepwizard-step .first").attr("href", linkpage0);
                        $(".stepwizard-step .second").attr("href", linkpage1);
                        $(".stepwizard-step .third").attr("href", linkpage2);
                        $(".stepwizard-step .fourth").attr("href", linkpage3);
                        $(".stepwizard-step .fifth").attr("href", linkpage4);
                        $("#form-update-profile :input").prop("disabled", false);
                        $("#form-update-profile input").val('');
                        $('.save-4, .loading-4').toggle();
                    }
                });
            },
        });
    });
</script>