innerHTML with For Loop in Javascript

后端 未结 2 1244
遇见更好的自我
遇见更好的自我 2021-01-03 06:44

this is my coding. in this coding i want to print table in innerHTML in

paragraph tag.This is working but the problem is when i click submit button this result show only

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 07:10

    Your for loop is overwriting the innerHTML of demop each time it is executing. So when your for loop reaches last iteration a will be 10 and hence you only get the last value "10*10=100"

    So you should append the result every time you iterate your for loop just make it like this

    demop.innerHTML += (value + "*" + a + "=" + (value*a) + "
    ");

    So you will get your output on seperate lines.

提交回复
热议问题