Why won't the change in CSS styling caused by JavaScript remain after script finishes running?

前端 未结 2 1697
说谎
说谎 2021-01-27 15:56

Edit: Title makes more sense now.

I\'m currently writing basic CRUD functionality using a popular web framework. In the edit section of my app, I have a \'Delete\' butto

相关标签:
2条回答
  • 2021-01-27 16:47
    1. You click the button
    2. The JavaScript runs and modifies the DOM loaded into the browser
    3. The form submits (because you clicked a submit button)
    4. The browser loads a new page (which doesn't have the changes you made to the DOM with JS because they were only local)

    If you don't want to submit the form when you click the button, don't use a submit button. Add type="button".

    0 讨论(0)
  • 2021-01-27 17:02

    When your form submits, the page refreshes and you thus need to reapply the js/css changes on document load... or submit using AJAX and change the input type from submit to button / or return false on clicking the submit button.

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