Set content of HTML with Javascript

前端 未结 4 723
旧巷少年郎
旧巷少年郎 2020-12-02 19:52

In a webpage I am calling a WebService that gives me an integer value. I need to display this value in a block of text. I am currently using an HTML

4条回答
  •  清歌不尽
    2020-12-02 20:33

    To do it without using a JavaScript library such as jQuery, you'd do it like this:

    var span = document.getElementById("myspan"),
        text = document.createTextNode(''+intValue);
    span.innerHTML = ''; // clear existing
    span.appendChild(text);
    

    If you do want to use jQuery, it's just this:

    $("#myspan").text(''+intValue);
    

提交回复
热议问题