我在计时器的第二次运行时重置计时器时遇到问题它总是说它不是一个功能你可以帮我吗
<div class="">
<div class="col-md-12" style="background-color: #ffcc80; margin-bottom: 5px; border-radius: 5px;">
<strong>idle: </strong><span id = "ctr_idle">0</span>
</div>
<div class="col-md-12" style="background-color: #ff9980; margin-bottom: 5px; border-radius: 5px;">
<strong>talk_time: </strong><span id = "ctr_talk">0</span>
</div>
<div class="col-md-12" style="background-color: #66c2ff; margin-bottom: 5px; border-radius: 5px;">
<strong>ON HOLD: </strong><span id = "ctr_hold">0</span>
</div>
<div class="col-md-12" style="background-color: #99e699; margin-bottom: 5px; border-radius: 5px;">
<strong>AFTERTALK: </strong><span id = "ctr_aftertalk">0</span>
</div>
<div class="col-md-12" style="background-color: #ffff99; margin-bottom: 5px; border-radius: 5px;">
<strong>TOTAL: </strong><span id = "ctr_total">0</span>
</div>
</div>
答案 0 :(得分:0)
首先是有重复的功能 count_aftertalk 所以我注释掉并更改了变量函数声明类型。你可以将它与旧代码进行比较,然后你就可以得到它。
使用此代码我希望它能够正常工作它不会显示它不是功能
var timer_idle;
var timer_talk;
var timer_hold;
var timer_aftertalk;
var count_idle;
var count_talk;
var count_hold;
var count_aftertalk;
var zero = parseInt("0");
count_idle = function (sec) {
clearInterval(timer_idle);
clearInterval(timer_talk);
timer_idle = setInterval(function() {
$('#ctr_idle').text(sec++);
}, 1000);
}
count_talk = function (sec) {
clearInterval(timer_idle);
timer_talk = setInterval(function() {
$('#ctr_talk').text(sec++);
}, 1000);
}
count_hold = function (sec) {
clearInterval(timer_talk);
timer_hold = setInterval(function() {
$('#ctr_hold').text(sec++);
}, 1000);
}
count_aftertalk = function (sec) {
clearInterval(timer_talk);
timer_aftertalk = setInterval(function() {
$('#ctr_aftertalk').text(sec++);
}, 1000);
}
/*function count_aftertalk(sec) {
clearInterval(timer_talk);
timer_aftertalk = setInterval(function() {
$('#ctr_aftertalk').text(sec++);
}, 1000);
}*/
count_idle(zero);
$("#reset").click(function() {
count_idle(zero);
$('#ctr_talk').text(0);
$('#ctr_hold').text(0);
$('#ctr_aftertalk').text(0);
$('#ctr_total').text(0);
console.log(count_talk);
});
$("#start").click(function() {
clearInterval(timer_idle);
count_talk(zero);
});
$("#hold").click(function() {
clearInterval(timer_talk);
num = $('#ctr_hold').text();
count_hold(num);
});
$("#unhold").click(function() {
clearInterval(timer_hold);
num = $('#ctr_talk').text();
count_talk(num);
});
$("#finish").click(function() {
clearInterval(timer_talk);
num = $('#ctr_aftertalk').text();
count_aftertalk(num);
});
$("#total").click(function() {
clearInterval(timer_aftertalk);
talk = parseInt($('#ctr_talk').text());
hold = parseInt($('#ctr_hold').text());
aftertalk = parseInt($('#ctr_aftertalk').text());
sum = talk + hold + aftertalk;
count_total = $('#ctr_total').text(sum);
});