Javascript, page keeps refreshing after outputting results

前端 未结 3 1451
猫巷女王i
猫巷女王i 2021-01-16 01:14

i have a small problem.

I\'m learning Javascript and I decided to make a currency converter but, my page keeps refreshing after the data is being displayed.

3条回答
  •  误落风尘
    2021-01-16 01:55

    The default behavior of button is act like a submit button if it's inside a form. If you add type='button', it stops acting like a submit button

    You can also just return false from the handler (like you could with ) to prevent the default behavior.

    Not that you don't really need a form here, since you're not submitting it. Removing the form also fixes your problem.

    See How to prevent buttons from submitting forms

提交回复
热议问题