【发布时间】:2013-10-31 21:01:18
【问题描述】:
我的问题是:我有两个 jquery 函数,它们都填写表单中的字段。目前它们同时运行,但我怎样才能让它在第一个脚本完成后才运行第二个脚本?
var string = 'joe@quadwtech.com',
letters = string.split(''),
total = letters.length,
index = 0,
timer = setInterval(function () {
if (index < total) {
$('input[name="email"]').val(function () {
return $(this).val() + letters[(index++)];
});
} else {
clearInterval(timer);
}
}, 100);
var stringtwo = 'Jason',
ttert = stringtwo.split(''),
totaltwo = ttert.length,
countt = 0,
timer = setInterval(function () {
if (countt < totaltwo) {
$('input[name="first"]').val(function () {
return $(this).val() + ttert[(countt++)];
});
} else {
clearInterval(timer);
}
}, 100);
【问题讨论】:
-
你可以设置不同的定时器吗?或者,完成后将第二个函数放入第一个函数中?
-
你正在覆盖你的
timervar,仅供参考
标签: jquery