以下 javascript 代码从数组中随机选择值并将其输入到输入框中。我用过jquery。我想结束 setInterval "zaman2",所以在它结束后我可以在输入框中重新输入下一个随机字符串。但是循环并没有结束并且卡住了。我该如何解决这个问题?链接到 jsFiddle:http: //jsfiddle.net/AQbq4/4/
var dersler = [...very long list...];
var zaman = setTimeout(function() {
var yeniDers = dersler[Math.floor(Math.random()*dersler.length)];
sayac = 0;
var zaman2 = setInterval(function() {
var harf = yeniDers.slice(0,(sayac+1));
sayac++;
$('#main-search').attr('placeholder', harf).typeahead({source: dersler});
if (sayac == yeniDers.length) {
clearInterval(zaman2);
}
},450);
},2000);