Obviously, There was a typo. Fixed:
1.
var i;
for (i=0;i<5;i++) {
setTimeout(function() {alert('first '+i);},5000);
}
2.
for (i=0;i<5;i++) {
(function(num) {
setTimeout(function() {alert('second '+num);},
500
I think you're having trouble with a closure. It's a common problem
and I recently got help on it myself.
JavaScript looks like C, but it's not C (or Java). You'll probably
keep running into this kind of thing until you understand closures, so
go ahead and search for "javascript closure" on googl
for (var x = 0; x < 10; x++) {
if ( x > 5) {
break;
}
}
Shawn
Alex wrote:
Hi, I am this script:
for (var i=0; i < 6; i++)
{
$('a#chan'+i).click(function(){
for (var j=0; j<6; j++)
{
$('a#chan'+j).r
3 matches
Mail list logo