This code doesn’t work
jQuery.each(["Alloggio","Macchina","Aereo","Treno"], function(){
t = this;
$("#ChkPrenotazione" + t + "Default").change(function(){
$(".Chk" + t).val($(this).val());
});
});
I want that t inner on change event is equal to “Alloggio” or “Macchina” or “Aereo” or “Treno”
How can i fix it?
thanks
You need to store the
tlocally. This can be done with a closure:Here we use the function
function(t) { … }to return a function with our correspondingthis. This is done by calling that function withthisas the parameter fort.