.submit()

.submit( handler )Returns: jQuery

Description: Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.

This method is a shortcut for .on( "submit", handler ) in the first variation, and .trigger( "submit" ) in the third.

The submit event is sent to an element when the user is attempting to submit a form.

It can only be attached to <form> elements. Forms can be submitted either by clicking an explicit <input type="submit">, <input type="image">, or <button type="submit">, or by pressing Enter when certain form elements have focus.

Depending on the browser, the Enter key may only cause a form submission if the form has exactly one text field, or only when there is a submit button present. The interface should not rely on a particular behavior for this key unless the issue is forced by observing the keypress event for presses of the Enter key.

For example, consider the HTML:

<form id="target" action="destination.html">
<input type="text" value="Hello there">
<input type="submit" value="Go">
</form>
<div id="other">
Trigger the handler
</div>

The event handler can be bound to the form:

$( "#target" ).submit(function( event ) {
alert( "Handler for .submit() called." );
event.preventDefault();
});

Now when the form is submitted, the message is alerted. This happens prior to the actual submission, so we can cancel the submit action by calling .preventDefault() on the event object or by returning false from our handler. We can trigger the event manually when another element is clicked:

$( "#other" ).click(function() {
$( "#target" ).submit();
});

After this code executes, clicks on Trigger the handler will also display the message. In addition, the default submit action on the form will be fired, so the form will be submitted.

The JavaScript submit event does not bubble in Internet Explorer.

However, scripts that rely on event delegation with the submit event will work consistently across browsers as of jQuery 1.4, which has normalized the event's behavior.

Additional Notes:

  • As the .submit() method is just a shorthand for .on( "submit", handler ), detaching is possible using .off( "submit" ).
  • Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems, see DOMLint.

jQuery .submit()的更多相关文章

  1. jquery submit选择器 语法

    jquery submit选择器 语法 作用::submit 选择器选取类型为 submit 的 <button> 和 <input> 元素.如果 <button> ...

  2. jquery submit事件

    jquery submit 事件 $('#form').submit(function(){ if(true){ //do return true; }else{ //do return false; ...

  3. jquery submit()不能提交表单的解决方法

    <form id="form" method="get"> <input type="text" name="q ...

  4. jquery submit ie6下失效的原因分析及解决方法

    ie6中, $('a.btn').click(function(){ form.submit(); }) 点击失效: 分析: 微软低版本浏览器会先执行link标签的自身事件也就是href事件,这样就中 ...

  5. jquery submit() 提交失败

    今天写一个表单提交 居然走到$('#wechat_form').submit() 这,但怎么都没有提交这个表单 google 了一下 Additional Notes:Forms and their ...

  6. jquery submit()不执行

    好吧我承认我竟然犯低级错误了...我忏悔...为了提醒自己置顶一个礼拜 <form id="form" method="post"> <inp ...

  7. jquery 之选择器

    一.基本: HTML代码: <p class="p1">p段落</p> <h class="h1">h标签</h> ...

  8. Web开发——jQuery基础

    参考: 参考W3School:jQuery 教程 参考:jQuery 参考手册 参考(常用):jQuery API 测试 JavaScript 框架库 - jQuery 测试 JavaScript 框 ...

  9. jQuery常用事件方法详解

    目录 jQuery事件 ready(fn)|$(function(){}) jQuery.on() jQuery.click jQuery.data() jQuery.submit() jQuery事 ...

随机推荐

  1. 虚拟机无法启动,提示:无法打开内核功能扩展“com.vmware.kext.vmci”: 无此文件或目录

    打开 系统偏好设置->安全性与隐私->允许打开 即可

  2. O008、LVM类型的Storage Pool

    参考https://www.cnblogs.com/CloudMan6/p/5277927.html   LVM类型的Storage Pool   不仅一个文件可以分配给客户机作为虚拟磁盘,宿主机上  ...

  3. Mybatis实际练习

    1.mybatis在xml文件中处理大于号小于号的方法 第一种方法: 用了转义字符把>和<替换掉,然后就没有问题了. SELECT * FROM test WHERE 1 = 1 AND ...

  4. shell awk读取文件中的指定行的指定字段

    1.awk功能和实用形式 awk指定读取文件中的某一行的某个字段 awk      可以设置条件来输出文件中m行到n行中每行的指定的k字段,使用格式如下 awk    'NR==m,NR==n {pr ...

  5. python-迭代器与生成器3

    python-迭代器与生成器3 迭代器可以直接作用于for循环的数据类型有以下几种: 一类是集合数据类型,如list.tuple.dict.set.str等: 一类是generator,包括生成器和带 ...

  6. Java并发(基础知识)—— Executor框架及线程池

    在Java并发(基础知识)—— 创建.运行以及停止一个线程中讲解了两种创建线程的方式:直接继承Thread类以及实现Runnable接口并赋给Thread,这两种创建线程的方式在线程比较少的时候是没有 ...

  7. 孕期出血是否先兆流产——B超看婴儿是否在子宫内+hcg值是否过低孕激素不足

    转自:http://blog.sina.com.cn/s/blog_4a869c130102e7nu.html 很多人都经历过孕早期阴道出血,但结局大不一样. 人类受孕后,从一个单细胞逐渐发育成为一个 ...

  8. MYSQL数据库事务4种隔离级别及7种传播行为

    事务的特性: 原子性:事务的不可分割,组成事务的各个逻辑单元不可分割. 一致性:事务执行的前后,数据完整性保持一致. 隔离性:事务执行不应该受到其他事务的干扰. 持久性:事务一旦结束,数据就持久化到数 ...

  9. 使用IDEA搭建一个Spring + AOP (权限管理 ) + Spring MVC + Mybatis的Web项目 (零配置文件)

    前言: 除了mybatis 不是零配置,有些还是有xml的配置文件在里面的. 注解是Spring的一个构建的一个重要手段,减少写配置文件,下面解释一下一些要用到的注解: @Configuration  ...

  10. 当心JavaScript奇葩的逗号表达式

    看看下面的代码输出什么? let a = 2; switch (a) { case (3, 2, 5): console.log(1); break case (2, 3, 4): console.l ...