Why does the reset button on html forms not reset hidden fields?

前端 未结 4 1069
醉梦人生
醉梦人生 2021-01-04 06:07

I discovered something surprising:





        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 07:02

    When clicking on reset, the browser goes and check the default value in the DOM tree, not in the HTML page.

    Your Javascript modifies the DOM. You should try to replace your RESET button with a custom button that calls a Javascript that does two things:

    • reset normally.
    • set the hidden field to 5.

提交回复
热议问题