计数计时器JavaScript

计数计时器JavaScript,javascript,timer,Javascript,Timer,非常熟悉javascript,并且一直在研究如何让计数计时器工作。 这里是我的JSFIDLE的链接。如果能得到一些关于问题的反馈,那就太棒了。 谢谢 $(函数(){ var arr= ["https://botanicalappbeta.s3.amazonaws.com/uploads/plant_photo/image/1512/paphioacmodontum.jpg", "https://botanicalappbeta.s3.amazonaws.com/uploads/plant_ph

非常熟悉javascript,并且一直在研究如何让计数计时器工作。 这里是我的JSFIDLE的链接。如果能得到一些关于问题的反馈,那就太棒了。 谢谢


$(函数(){
var arr=
["https://botanicalappbeta.s3.amazonaws.com/uploads/plant_photo/image/1512/paphioacmodontum.jpg", "https://botanicalappbeta.s3.amazonaws.com/uploads/plant_photo/image/1250/aechmea1.jpg"];
$(“#puzzle div”).css({'background-image':'url('+arr[Math.floor(Math.random()*arr.length)]+');
var拼图=$(“#拼图”);
var碎片=$(“#拼图分割”);
工件排序(函数(a,b){
var temp=parseInt(Math.random()*100);
var isOddOrEven=temp%2;
变量IsPosoreng=温度>5?1:-1;
返回(isOddOrEven*isposoreng);
}).附录(拼图);
无功定时器;
var-secs=0;
var-mins=0;
var timeField=document.getElementById(“时间”);
timeField.innerHTML=“00:00”;
函数更新(){
如果(秒=59){
mins++;
秒=0;
} 
否则{
secs++;
}

if(secs它应该是
if(secs==59)
而不是
if(sec==59)
,因为变量名为
secs

…那么怎么了?
<script type="text/javascript">
$(function () {
var arr = 
["https://botanicalappbeta.s3.amazonaws.com/uploads/plant_photo/image/1512/paphioacmodontum.jpg", "https://botanicalappbeta.s3.amazonaws.com/uploads/plant_photo/image/1250/aechmea1.jpg"];

$("#puzzle div").css({'background-image':'url(' +arr[Math.floor(Math.random()*arr.length)] + ')'});

var puzzle = $("#puzzle");
var pieces = $("#puzzle div");

pieces.sort(function (a, b) {
    var temp = parseInt(Math.random() * 100);
    var isOddOrEven = temp % 2;
    var isPosOrNeg = temp > 5 ? 1 : -1;
    return (isOddOrEven * isPosOrNeg);
}).appendTo(puzzle);

var timer;
var secs = 0;
var mins = 0;
var timeField = document.getElementById("time");
timeField.innerHTML = "00:00";

function update(){
if(sec == 59){
    mins++;
    secs = 0;
} 
else {
    secs++;
}
if(secs<10){
    timeField.innerHTML = mins + ':0' + secs;
} 
else {
    timeField.innerHTML = mins + ':' + secs;
}   
}

function start(){
timer = setInterval(function() {update()}, 1000);
}

start();    
initSwap();

function initSwap() {
initDroppable($("#puzzle div"));
initDraggable($("#puzzle div"));
}


function initDraggable($elements) {
$elements.draggable({
    appendTo: "body",
    helper: "clone",
    cursor: "move",
    revert: "invalid"
});
}

function initDroppable($elements) {
$elements.droppable({
    activeClass: "ui-state-default",
    hoverClass: "ui-drop-hover",
    accept: ":not(.ui-sortable-helper)",
    over: function (event, ui) {
        var $this = $(this);
    },
    drop: function (event, ui) {
        var $this = $(this);
        var linew1 = $(this).after(ui.draggable.clone());
        var linew2 = $(ui.draggable).after($(this).clone());
        $(ui.draggable).remove();
        $(this).remove();
        initSwap();
    }
});
}
});
</script>