Vous pouvez faire:
$("input.txt").focus() {
$("label[for='" + this.id + "']").addClass("highlight");
}).blur(function() {
$("label[for='" + this.id + "']").removeClass("highlight");
});
avec:
label.highlight { background: yellow; font-weight: bold; }
Lorsqu'un champ d'entrée a le focus, son étiquette (en supposant qu'il en a un) est mis en évidence.
Edit: Pour parcourir les entrées et faire quelque chose avec les étiquettes:
$(":input[id]").each(function() {
if ($(this).val() != '') {
$("label[for='" + this.id + "'").each(do_something);
}
});
function do_something() {
// this refers to the label
}
ou simplement:
$(":input[id]").each(function() {
if ($(this).val() != '') {
$("label[for='" + this.id + "'").addClass("notnull");
}
});
ou vous pouvez aller dans l'autre:
$("label[for]").each(function() {
var label = this;
$("#" + $(this).attr("foo") + ":input").each(function() {
if ($(this).val() != "") {
$(label).addClass("notnull");
}
});
});
Que signifie «changer st dans l'étiquette d'étiquette associée»? – psychotik
désolé pour l'obscur – anhtran