I have form for which I want to apply some validations on all text fields and Select fields. I want to know when the blur event is called it is raised by which field. I am using the below given code.
$(document).ready(function() {
$("select").blur(function() {
// alert("ID "+,$(this).attr('id'));
var selected = $("#tabs").tabs('option', 'active');
var selectedTabTitle = $($("#tabs li")[selected]).text();
skip_test(selectedTabTitle);
});
$("input").blur(function() {
var selected = $("#tabs").tabs('option', 'active');
var selectedTabTitle = $($("#tabs li")[selected]).text();
skip_test(selectedTabTitle);
});
});
$(this)
should always point to the element which fired the event
for example $(this).addClass("failedValidation")
Also if you can add a class to all the selects and inputs you will not need to repeat your code. If you can't you can define the function elsewhere and just refer to it in the blur()
e.g.
var doMyBlurStuff = function () {
$(this).addClass("failedValidation")
};
$("select, input").blur(doMyBlurStuff);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加