jQuery .submit()
.submit()
.submit( handler )Returns: jQuery
Description: Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.
version added: 1.0.submit( handler )
- handlerA function to execute each time the event is triggered.
version added: 1.4.3.submit( [eventData ], handler )
- eventDataType: AnythingAn object containing data that will be passed to the event handler.
- handlerA function to execute each time the event is triggered.
version added: 1.0.submit()
- This signature does not accept any arguments.
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, ormethod. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems, see DOMLint.
jQuery .submit()的更多相关文章
- jquery submit选择器 语法
jquery submit选择器 语法 作用::submit 选择器选取类型为 submit 的 <button> 和 <input> 元素.如果 <button> ...
- jquery submit事件
jquery submit 事件 $('#form').submit(function(){ if(true){ //do return true; }else{ //do return false; ...
- jquery submit()不能提交表单的解决方法
<form id="form" method="get"> <input type="text" name="q ...
- jquery submit ie6下失效的原因分析及解决方法
ie6中, $('a.btn').click(function(){ form.submit(); }) 点击失效: 分析: 微软低版本浏览器会先执行link标签的自身事件也就是href事件,这样就中 ...
- jquery submit() 提交失败
今天写一个表单提交 居然走到$('#wechat_form').submit() 这,但怎么都没有提交这个表单 google 了一下 Additional Notes:Forms and their ...
- jquery submit()不执行
好吧我承认我竟然犯低级错误了...我忏悔...为了提醒自己置顶一个礼拜 <form id="form" method="post"> <inp ...
- jquery 之选择器
一.基本: HTML代码: <p class="p1">p段落</p> <h class="h1">h标签</h> ...
- Web开发——jQuery基础
参考: 参考W3School:jQuery 教程 参考:jQuery 参考手册 参考(常用):jQuery API 测试 JavaScript 框架库 - jQuery 测试 JavaScript 框 ...
- jQuery常用事件方法详解
目录 jQuery事件 ready(fn)|$(function(){}) jQuery.on() jQuery.click jQuery.data() jQuery.submit() jQuery事 ...
随机推荐
- 关于redis的几件小事(三)redis的数据类型与使用场景
1.string 这是最基本的类型了,就是普通的set和get,做简单的kv缓存. 2.hash 这个是类似map的一种结构,这个一般就是可以将结构化的数据,比如一个对象(前提是这个对象没嵌套其他的对 ...
- 小P的架构生活(上)
背景:这年小P已经参加工作4年了,在前同事Z的极力劝说下,小P加入了Z新开的公司Y,公司一共有三个人:老板Z.程序员小P.前台W.项目名为XX交易系统 小P加班加点,终于在两个月后把系统开发完成,版本 ...
- dedecms 列表标签 去斜杠 去两边空格
首先:将 include/arc.listview.class.php 文件的第53行: $this->Fields['title'] = ereg_replace("[<> ...
- Delphi CheckBox组件
- ctfd搭建
CTFd 0x00 前言 搭个CTF平台,看能不能带动一下学校的CTF参与度. 一个下午都在搭这个平台:O 抓瞎摸索,最后成功用Apache+mod_wsgi也算是功德圆满了. 进入正题: 系统: C ...
- PAT Basic 1012 数字分类 (20 分)
给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: A1 = 能被 5 整除的数字中所有偶数的和: A2 = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 n ...
- xss过滤方法
用的白名单过滤,是我们的论坛自用的方法,也许考虑不周,欢迎来黑我们的论坛!https://www.ebcms.com/forum.html // 安全过滤 function safe_html($ht ...
- JavaScript基础——JavaScript语法基础(笔记)
JavaScript语法基础(笔记) 1.语言编码 JavaScript语言建立在Unicode字符集基础之上,因此脚本中,用户可以使用双字节的字符命名常量.变量或函数等. [示例] var 我=&q ...
- SessionFactory的openSession与getCurrentSession区别
SessionFactory 1 用来产生和管理sesssion 2 通常情况下,每个应用只需要一个SessionFactory,除非要访问多个数据库的情况 3 openSession()与openS ...
- 模意义下的FFT算法
//写在前面 单就FFT算法来说的话,下面只给出个人认为比较重要的推导,详细的介绍可参考 FFT算法学习笔记 令v[n]是长度为2N的实序列,V[k]表示该实序列的2N点DFT.定义两个长度为N的实序 ...