i am in trouble with javascript‘s callback,my code seems simple:
var i =0;
for (; i < listSize+1; i++) {
var content = "content"+i;
$("#" + content).focus(function () {
$("#" + content).keydown(check(new Number(i)));
$("#" + content).keyup(check(new Number(i)));
});
}
where lisetSize=3 in my test case and content is the html element's id
and the callback function check(my_num) is:
function check(my_num) {
var content = "content"+my_num;
}
then i try to trigger this function through keyboard input.
however,i got the result that content=content4 all the time via my broswer's debugger,even though the listening element is content0
i have try anyway such as $.extend({},i) $.extend(true,{},i)
it make no difference
now i have no idea about this problem,how can i just pass a value but no reference to the callback function's parameter?