for loop works fine with console.log but not innerHTML?

后端 未结 2 1097
南笙
南笙 2021-01-24 22:07

hello i\'m very new to javascript so forgive me if the answer seems obvious...

this is my code which is executed at the click of a button in the body

fun         


        
2条回答
  •  粉色の甜心
    2021-01-24 22:47

    function q() { 
    
        var A = +document.getElementById("time_one").value;
        var B = +document.getElementById("time_two").value;
        var C = +document.getElementById("post_number").value;
    
        var D = (B - A) / C;
    
        for ( var x = A; x < B; x = x + D ) {
    
        document.getElementById("q_box").innerHTML += x + "
    "; } }

    You should convert the values in int and you should use +=

提交回复
热议问题