[英]JQuery focusOut issue in IE
I have a small problem with focusout
function in IE. 我在IE中的
focusout
功能有个小问题。
I have two fields with the same class and I wrote an empty validation code in jQuery for that class with focusout
. 我有两个具有相同类的字段,并且我在jQuery中使用
focusout
在该类中编写了一个空验证代码。
While I focus out of a field which is empty it shows alert and focus to the same field. 当我将重点放在一个空字段上时,它会显示警报并将焦点集中在同一字段上。
While doing that focus, It shows me alert again and again b'coz of the same class. 在做这个重点的同时,它向我展示了一次又一次的同等级b'coz警报。
What to do? 该怎么办?
JS: JS:
$(".emptyValidate").focusout(function() {
var currFocusOut = $(this).attr("inText");
if($(this).val() == ""){
alert(currFocusOut+" should not be Empty");
document.getElementById(currFocusOut).focus();
}
});
Markup : 标记:
<input type="text" inText="Name" id="Name" class="emptyValidate "/>
<input type="text" inText="Phone" id="Phone" class="emptyValidate "/>
$(".emptyValidate").focusout(function () {
var currFocusOut = $(this).attr("id");
if ($(this).val() == "") {
alert(currFocusOut + " should not be Empty");
$('#'+currFocusOut).focus();
}
});
Try to use blur function
like, 尝试使用
blur function
例如
$(".emptyValidate").blur(function() {
var currFocusOut = $(this).attr("inText");
if($(this).val() == ""){
alert(currFocusOut+" should not be Empty");
document.getElementById(currFocusOut).focus();
}
});
Or, custom attribute inText
may not work, so you can use data
in jquery
like 或者,自定义属性
inText
可能不起作用,因此您可以在jquery
使用data
,例如
<input type="text" data-inText="Name" id="Name" class="emptyValidate "/>
<input type="text" data-inText="Phone" id="Phone" class="emptyValidate "/>
$(".emptyValidate").focusout(function() { // use blur if not works
var currFocusOut = $(this).data("inText");
if($(this).val() == ""){
alert(currFocusOut+" should not be Empty");
document.getElementById(currFocusOut).focus();
}
});
Try inline function like this: 试试这样的内联函数:
<input type="text" inText="Name" id="Name" class="emptyValidate" onfocusout="myFunction(this)"/>
<input type="text" inText="Phone" id="Phone" class="emptyValidate" onfocusout="myFunction(this)"/>
function myFunction(el){
var currFocusOut = $(el).attr("inText");
if($(el).val() == ""){
alert(currFocusOut+" should not be Empty");
document.getElementById(currFocusOut).focus();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.