Writing text on “div” using JavaScript

后端 未结 10 2416
难免孤独
难免孤独 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:37

    change this

    <input type="submit" value="Ready!" onClick="writeComment()" /> 
    

    to this:

    <input type="submit" value="Ready!" onClick="writeComment(); return false;" /> 
    
    0 讨论(0)
  • 2021-01-04 02:39

    try <input type="button" value="Ready!" onClick="writeComment()" />

    0 讨论(0)
  • 2021-01-04 02:44

    This is because you use not just a regular button but a submit button which by default submits the form to the server. You can see that your comment is submitted via URL as you didn't specify the method(GET and POST and GET is default).

    Simply write:

    onclick="writeComment();return false;"
    

    Returning FALSE prevents from default behaviour - submitting the form.

    0 讨论(0)
  • 2021-01-04 02:44

    you should switch
    <input type="submit" value="Ready!" onClick="writeComment()" />
    for
    <input type="button" value="Ready!" onClick="writeComment()" />

    0 讨论(0)
提交回复
热议问题