我正在将此JavaScript代码与JQuery Library一起使用,现在这不适用于 Google Chrome ,适用于 Apple Safari 和 FireFox (经测试)
$(document).on('blur', '#UserNameInput', function(e) {
//alert ('this')
if ($(this).val().length < 6 ) {
$('#UnameCheck').html('That user anme is too short... please try again with something more than 6 Charecters')
} else {
$(this).css('background-image', 'url(../images/IMG_8485.GIF)');
$('#UnameCheck').html('Please wait while checking your User Name').css('color', '#F3F').show('fast');
var Uname = ($('#UserNameInput').val())
var data = { // create object
l : Uname
}
$.ajax({
type:"POST",
data: data,
complete: function(){
$('#UserNameInput').css('background-image', '')
},
url:"../php/UserNameCheck.php"
}).done(function(feedback){
$('#UnameCheck').html(feedback)
});
}
});
答案 0 :(得分:2)
在您的情况下,要符合Chrome要求,您需要添加mouseup
事件,或/和mouseleave
:
$(document).on('blur mouseup mouseleave', '#UserNameInput', function (e) {
//alert ('this')
if ($(this).val().length < 6) {
$('#UnameCheck').html('That user anme is too short... please try again with something more than 6 Charecters');
} else {
$(this).css('background-image', 'url(../images/IMG_8485.GIF)');
$('#UnameCheck').html('Please wait while checking your User Name').css('color', '#F3F').show('fast');
var Uname = ($('#UserNameInput').val());
var data = { // create object
l: Uname
};
$.ajax({
type: "POST",
data: data,
complete: function () {
$('#UserNameInput').css('background-image', '');
},
url: "../php/UserNameCheck.php"
}).done(function (feedback) {
$('#UnameCheck').html(feedback);
});
}
});
答案 1 :(得分:0)
对于FF Mac,Saf Win,Chrome Win和Chrome Mac,blur
事件不完整。
如these event compatibility tables中所列。
使用其他完整的事件监听器(例如mouseleave
和mouseup
)可以解决问题。