我有一个对 pincode 进行验证的应用程序。 当验证错误时,会显示错误消息,但随后会将 pincode 保留在字段中并失去焦点。 当您第一次在模态中输入密码时,它会正常聚焦并打开模态键盘。当你必须再次填写密码时我想要同样的东西。 下面的代码用于聚焦和验证:
验证:
$('#suspend_sale').click(function() {
var custID = $("#spos_customer").val(),
pin = $("#reference_note").val();
$.ajax({
url: base_url + 'customers/validatePin',
data: {
custID: custID,
pin: pin
},
type: "get",
dataType: 'json',
success: function(response) {
if(response.valid) {
$('#hold_ref').val($('#reference_note').val());
$('#total_items').val(an - 1);
$('#total_quantity').val(count - 1);
$('#submit').click();
} else {
$("#ref_error_msg").show(function(){
setTimeout(function(){
$("#ref_error_msg").hide('slow');
}, 1000);
});
}
},
error: function() {
bootbox.alert(lang.customer_request_failed);
return false;
}
});
return false;
});
首先关注输入字段:
$('#susModal').on('shown.bs.modal', function () {
// clear input field, set focus and click to make keyboard appear
$('#reference_note').val('').focus().click();
});
谢谢
最佳答案
你只需像这样改变你的jquery。删除点击()
$('#susModal').on('shown.bs.modal', function () {
// clear input field, set focus and click to make keyboard appear
$('#reference_note').val('');
$('#reference_note').focus();
});
工作正常
关于php - 验证后返回带有焦点的空字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35650022/