不能使用jquery禁用锚标签.没有"disabled&;也不能在ajax调用()期间使用e.p preven
can't disabled anchor tags using jquery... nither with "disabled" nor with e.preventDefault() during ajax call()
现在只有问题没有禁用锚标记,我有包括ajax提交库,现在正在工作,我只想在处理期间禁用锚,但我不能禁用"disable"也不能使用e.p 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>
好像少了一个逗号。
请换
cpassword :"Password not matched"
}
submitHandler: function() {
cpassword :"Password not matched"
},
submitHandler: function() {
javascript中的消息块后面缺少逗号。
我已经标准化了代码的缩进,这样更容易阅读。这也使得更容易发现错误。
另外,冒号周围有不一致的空格,所以我也整理了这些。
编辑:jQuery匹配输入的id,而不是名称。
<script>
function savepassword() {
$('#password').validate({ // initialize the plugin
rules: {
password: {
required: true,
minlength: 6
},
cpassword: {
equalTo: "#inputfield1"
}
},
messages: {
password: " Enter Password with 6 minimum characters",
cpassword: "Password not matched"
},
submitHandler: function() {
$('.save-2, .loading-2').toggle();
$.ajax({
type: "POST",
url: "<?php echo base_url('user/save_password'); ?>",
data: {
password: $('#password input[name="password"]').val(),
cpassword: $('#password input[name="cpassword"]').val()
},
success: function (result) {
console.log(result);
}
});
$('.save-2, .loading-2').toggle();
}
});
}
</script>
这不是你要求的。但是,在处理过程中禁用页面或部分的最佳方法是使用css添加覆盖元素,并且最好带有加载图标。这将避免所有的麻烦,并提供更好的显示。
感谢所有我通过复制所有删除href,然后再次添加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>
相关文章:
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 如何从Java/scala调用js美化程序
- 如何调用这个匿名 JavaScript 函数
- 如何从模块链中调用函数.导出到节点中
- 我需要从php调用javascript或jquery
- Chrome开发工具(如何知道我在调用哪个javascript对象)
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- node.js:setInterval()正在跳过调用
- 如何在单击复选框后调用控制器方法
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 使用Google Visualization动态调用构造函数
- 如何在webView,Android中从@JavascriptInterface方法调用Javascript
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 调用函数内部的函数
- 函数未在Object.keys或Object.getOwnPropertyNames下列出,但可以调用
- Javascript/jQuery中的并行Ajax调用
- 不能使用jquery禁用锚标签.没有"disabled&;也不能在ajax调用()期间使用e.p preven