How to make background color of div tag keep changing using JQuery?

前端 未结 3 1959
再見小時候
再見小時候 2020-12-21 07:59

I am trying to change background of div tag continuously using for loop and rgb() values . following is my code written in sample.html:

    

        
3条回答
  •  渐次进展
    2020-12-21 08:51

    Everything seems fine besides the code where you set the CSS.

    Change the code :

    $("#sqr").css("background-color","rgb(r,g,b)");
    

    To :

    $("#sqr").css("background-color","rgb(" + r + "," + g + "," + b + ")");
    

    This will now pass in the number values, i.e.

    $("#sqr").css("background-color","rgb(254,254,254)");
    

    Where as before it would have simply passed the values r,g,b because you placed them within a string.

提交回复
热议问题