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事 ...
随机推荐
- 二叉树的C++实现
这是去年的内容,之前放在github的一个被遗忘的reporsity里面,今天看到了就拿出来 #include<iostream> #include<string> using ...
- 一个java文件中有几个类,编译后有几个class文件?
在一个源文件中用class关键字定义了几个类,编译的时候就会产生几个字节码文件
- 红色警戒2CE修改教程
在大学的时候特别喜欢玩游戏,尤其偏爱单机游戏.在玩一些单机游戏的时候,特意使用了一些修改工具.本来是打算做成一个系列的,但是现在由于时间问题,仅介绍一些.(大概包括rimworld,饥荒,放逐之城,缺 ...
- 免费使用Google
这里需要借助一下`梯子`,这里有教程 点击进入 如果没有谷歌浏览器,进入下载最新版谷歌浏览器,进入下载,不要移动它的安装位置,选择默认位置, 如果已经安装了谷歌浏览器,打开赛风之后,选择设置 进行安装 ...
- 常见shell用法
分析nginx访问日志 awk '{a[b[$1]++]}END{for(i=length(a);i>0;i--)for(j in b)if(b[j]==i){c++;if(c<=10)p ...
- Linux 性能优化笔记:软中断(转载)
进程的不可中断状态是系统的一种保护机制,可以保证硬件的交互过程不被意外打断. 所以,短时间的不可中断状态是很正常的. 但是,当进程长时间都处于不可中断状态时,你就得当心了.这时,你可以使用 dstat ...
- js 点击不同li 切换颜色
html <div> <li " onclick='addColor(this.id)'> 会议简介 </li> <li " onclic ...
- Javascript引擎
注入了 浏览器对象模型BOM, 文档对象模型DOM
- WTL自定义控件:SubclassWindow的实现
自定义了一个edit类如下: class CCheckEditEx : public CWindowImpl< CCheckEditEx, CEdit > 其SubclassWindow函 ...
- 如何解决tab栏切换只发一次请求的问题
用的antd的tab栏组件,发现切换tab栏只在componentDidMount里面发了一次请求,后来发现是缓存问题,于是用activeKey再次进行了判断,代码如下: