Writing text on “div” using JavaScript

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

    When you click on the submit button the form is submitted, causing the whole page to reload. You need to return false from the onclick of the submit button to prevent it:

    
    

    Or, if you don't want the button to ever submit the form change type="submit" to type="button".

    PS. It's bad practice to use the onclick attribute. Instead bind a handler to the click event using pure JS.

提交回复
热议问题