How to print one specific Javascript variable in HTML?

前端 未结 3 488
故里飘歌
故里飘歌 2021-01-25 16:51

I want to ask how I can print a Javascript variable in HTML form (e.g. output it on the screen)?

Here is my JS code:



        
3条回答
  •  逝去的感伤
    2021-01-25 17:37

    Set it to be the innerHTML or value of a html element:

    var howLongIsThis = myPlayer.duration();
    var displayEl = document.getElementById("duration");
    displayEl.innerHTML = howLongIsThis;
    

    or if you want in in a form field:

    displayEl.value = howLongIsThis;
    

提交回复
热议问题