Js timer cannot be cleared in WeChat Work H5 interface

this code may be fine in the browser, but on the H5 interface on the mobile side, the loop will always fail to stop

            function zhuajiu(userid) {
                var timesRun = 0;
                var ran = 0;
                var time = setInterval(function() {
                    ran = Math.random() * 100; //[0,range)
                    var result = parseInt(ran); //
                    $(".lotid").html(result);

                    timesRun += 1;
                    if(timesRun === 10) { 
                        alert(11);
                        clearInterval(time);
                    }

                }, 50);



            }

Thank you for your help. A global variable has been contaminated.

May.22,2021

seems strange. I misread


. Is there a recurrence address? Has it been called repeatedly? Pull out a separate page, is there the same question? Add a vconsole, to the


page to add alert (11); replace it with console.log (timesRun); or consider remote real machine debugging; in addition, if (timesRun = 10) I think it seems safer to write this as if (timesRun > = 10).

Menu