Why do I need form nested input?

the front end of a monk sees form nested input when looking at many projects, such as the following:

<form class="search_form">
  <input type="search" name="search" placeholder="" class="search_input" v-model="searchValue" @input="checkInput">
  <input type="submit" name="submit" class="search_submit" @click.prevent="searchTarget("")">
</form>

what is the purpose of form here? Initiating a request is also a request called in the event in @ click

Jun.01,2022

if you don't need a form submission, you don't have to write the form tag and add it for semantics to tell others that it's a form.


1. You can submit data using form forms when you are not using AJAX. For example, (PHP,JSP,ASP)
2, it is convenient to do data verification, you can use label for
3, and now you can basically not use form. For example, you may not use form


in your example.

it is convenient to get all the form data in form at once.

for example:

  <form id='form'>
    <input value="1" name="a" />
    <input value="2" name="b" />
    <input value="3" name="c" />
    <input value="4" name="d" />
  </form>

  <script>
    var inputs = document.getElementById("form").elements;
    var keyValues = {};
    for (var i = 0; i < inputs.length; iPP) {
      var input = inputs[i];
      keyValues[input.name] = input.value;
    }
    console.log(keyValues);
  </script>

use the form tag to configure method and action even when the browser's javascript is disabled, the page can simply interact with the server.

but nowadays, data is mostly submitted using XMLHTTPRequest objects, so it doesn't matter whether or not you use form .


if this code is
written on mobile and notice that the type of input is search
, then his purpose
may be to call up ios keyboard with search button

.

when ios calls up a keyboard with a [search] button, only writing type='search' does not work, it must be wrapped with a layer of form


HTML < form > tag

definition and usage

The

< form > tag is used to create an HTML form for user input.
forms can contain input elements, such as text fields, check boxes, radio boxes, submit buttons, and so on. The
form can also contain menus, textarea, fieldset, legend, and label elements. The
form is used to transfer data to the server.


my understanding is that form is mainly used for form submission. If you don't need a form submission. It doesn't matter whether you use form or not. It is OK to write input directly, then get the value entered in input and submit it by ajax.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5b639-45618.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5b639-45618.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?