为什么将<form>与jquery一起使用

If I am writing an application where I can dictate that the users must have a modern browser with javascript enabled, what is the benefit of using the html tag.

For instance if I submit all of my "forms" by doing something like this, but I don't actually have any form tags in my html. I just build a datalist to pass through the data parameter of the $.ajax call

$('#submit_form').click(function(){
   var datalist='foo='+$('#foo').val();
   $.ajax({
     // ajax json here
   });
}

Why would I use the form tag in my html code? I am sure there is probably a good reason, but a friend asked me the other day and I couldn't give him a good reason why it was needed.

  1. Your server side fallback will cause the form to continue to work if the JavaScript fails for some reason other than "the user has turned it off" (such as a network interruption)
  2. Having the fields logically grouped in a form will make them more easily navigable in most screen reader software.

that and also you can use the html 5 attribute such as "required" (not submitting the form if this field empty)

<input type="text" required = required />

or <input type="email"/> (make sure its a valid email address). without a form this attribute will not work. with this code you save a bunch of code in JS.

hope i helped.