2011-07-19 9 views
-1

3秒の新しいウィンドウ間隔を開く:Javascriptを:これは私のhtmlコードである

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>Something</title> 
</head> 
<body> 
    <a href="http://jquery.com/">Try Me!</a> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
    <script> 
$("a").click(function(event){ 

for(id=0;id<=10;){ 
id++; 
    setTimeout(function(){window.open("http://www.mysite.com/characterID="+id,"", "win1", "width=100,height=100,resizable");}, 3000); 
    } 
event.preventDefault(); 
}); 

    </script> 
</body> 
</html> 

私がクリックすると、 "私を試してみてください!"私は3秒後に必要なウィンドウを開きます。しかし、私は最初のウィンドウを開き、3秒待ってから2番目のウィンドウを開き、3秒待ってから3番目のウィンドウを開きます。

可能ですか?

ありがとうございます。

答えて

1

利用のsetIntervalの代わりに、setTimeoutを

0

お知らせ私はあなたの中にある反復の数によってタイムアウトを掛ける方法もforループの構文の違いに気づく:。

$("a").click(function(event){ 
    for(i = 0; i< 10; i++) 
     setTimeout(function(){window.open("http://www.mysite.com/characterID="+id,"", "win1", "width=100,height=100,resizable");}, 3000 * i); 
    } 
    event.preventDefault(); 
}); 
0
$("a").click(function(event){ 
    for(id=0;id<=10;id++){ 
    var local_id = id; 
    setTimeout(function() { 
     window.open("http://www.mysite.com/characterID="+local_id,"", "win"+local_id, "width=100,height=100,resizable"); 
     }, 3000*id); 
    } 
    event.preventDefault(); 
}); 

複数のIDでタイムアウトし、3秒後に各ウィンドウを開きます。

+0

いつもこのウィンドウ(http://www.mysite.com/characterID=10)が開きます。 私はその行が必要です。 http://www.mysite.com/characterID=0、http://www.mysite.com/characterID=1、http://www.mysite.com/characterID=2 ... –

+0

変更する必要があります"win1"から "win" + idの名前 –

+0

何も変更されていません。 –

関連する問題