Writing text on “div” using JavaScript

后端 未结 10 2550
难免孤独
难免孤独 2021-01-04 02:11

I\'m having some trouble whenever I want to add some text to my div tag, here\'s my code:




10条回答
  •  情歌与酒
    2021-01-04 02:25

    It is because you are submitting the form.

    Quick fix:

    
    

    to

    
    

    In addition, you are able to prevent the default action of an input. Basically telling the browser the you are going to handle the action with preventDefault:

    function writeComment(e) {
        var comment = document.forma.commentUser.value;
        alert(comment);
    
        document.getElementById('comments').innerHTML = comment;
        e.preventDefault();
        return false;
    }
    

提交回复
热议问题