what do <form action=“#”> and <form method=“post” action=“#”> do?

前端 未结 4 1425

I\'m reading a book on html development (which I\'m fairly new at) and despite the fact that the book just had its 1st publishing one month ago (Nov. 2011), the author is an

相关标签:
4条回答
  • 2020-11-27 12:26

    Apparently, action was required prior to HTML5 (and # was just a stand in), but you no longer have to use it.

    See The Action Attribute:

    When specified with no attributes, as below, the data is sent to the same page that the form is present on:

    <form>
    
    0 讨论(0)
  • 2020-11-27 12:39

    action="" will resolve to the page's address. action="#" will resolve to the page's address + #, which will mean an empty fragment identifier.

    Doing the latter might prevent a navigation (new load) to the same page and instead try to jump to the element with the id in the fragment identifier. But, since it's empty, it won't jump anywhere.

    Usually, authors just put # in href-like attributes when they're not going to use the attribute where they're using scripting instead. In these cases, they could just use action="" (or omit it if validation allows).

    0 讨论(0)
  • 2020-11-27 12:41

    The # tag lets you send your data to the same file. I see it as a three step process:

    1. Query a DB to populate a from
    2. Allow the user to change data in the form
    3. Resubmit the data to the DB via the php script

    With the method='#' you can do all of this in the same file.

    After the submit query is executed the page will reload with the updated data from the DB.

    0 讨论(0)
  • 2020-11-27 12:43

    Action normally specifies the file/page that the form is submitted to (using the method described in the method paramater (post, get etc.))

    An action of # indicates that the form stays on the same page, simply suffixing the url with a #. Similar use occurs in anchors. <a href=#">Link</a> for example, will stay on the same page.

    Thus, the form is submitted to the same page, which then processes the data etc.

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