HTML5 + Jscript with jQuery, setInterval problem

Please tell me why this does not work before I go around everything on my desk.

I have the following html document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html"; charset=utf-8 />
    <title>Sample Gauge using JQuery</title>
</head>
<body>
    <canvas id="gauge" width="200" height="200">
    Your web browser does not support HTML 5 because you fail.
    </canvas>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="gauge.js"></script>
</body>
</html>

And gauge.js:

$(document).ready(function () {
    //(canvas gets assigned)

    startRendering();

    function startRendering() {
        setInterval("render();", 1000);
    }

    function render() {
        renderBackground();
        renderNeedle(-172);
    }

    //(Defined functions for rendering a gauge)
});

render () is not called, but if I change the setInterval string only to "render ()", it does. Also, if I modify setInterval () to contain something like "alert (" LOL "), then it works, it just doesn't work with the functions that I defined. With or with a semicolon at the end of the function (functions ) for the call does not matter or prefix. to my functions.

I'm trying to get this working, so I can start using it to animate the sensor. Can anyone understand why it is not working?

I hate web development.

+3
2

    setInterval("render();", 1000);

    setInterval(render, 1000);

setInterval(), . . , , .

+2

, "render()" , .

function startRendering() {
    setInterval(function(){
        render()
    }, 1000);
}
0

Source: https://habr.com/ru/post/1765066/


All Articles