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事 ...
随机推荐
- Three.js类似于波浪的效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js 回顾知识总结一
1.js数据类型? 基本数据类型:String(字符串).boolean(布尔值).Number(数字).undefined(未定义).null(空) 引用数据类型:Object(对象).Array( ...
- QQ恶搞 - 卡死对方的手机QQ
方式1(低端设备有效): 使用方法: 代码: oo0.oo.OOO00.oo.OO00.oo.OO00.oo.OO00.oo.OO00.oo.OO00.oo.OO00.oo.OO00.oo.O00.o ...
- javascript join以及slice,push函数
1.join定义和用法 join() 方法用于把数组中的所有元素放入一个字符串. 元素是通过指定的分隔符进行分隔的. arrayObject.join(separator) separator:可选. ...
- 递推DP(至少和至多之间的转换
UVa 10328 - Coin Toss 题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 转换成抛N次至多连续有N个减去抛N次至多连续有K-1个1的情况 dp[i][k]表 ...
- 高性能mysql 第1章 mysql架构与历史
mysql逻辑架构图: 第一层 客户端 第二层(服务层):针对所有类型的存储引擎可以公共提取的部分.将存储引擎抽离之后的其他部分都在这里.如:查询解析,分析优化,内置函数,存储过程,触发器,视图. 第 ...
- idea 下获取路径下文件的方法
想读取resouce/temp下的test.txt文件.方式一:File sourceFile = ResourceUtils.getFile("classpath:temp/test.tx ...
- 【CF451E】Devu and Flowers
题目大意:求多重集合的组合数, \(N \le 1e14,M \le 20\). 题解: 考虑容斥原理,具体做法是枚举所有情况,即:枚举子集,第 i 位为 1 表示满足第 i 个条件,正负号采用 si ...
- Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器
[文章作者:张宴 本文版本:v6.3 最后修改:2010.07.26 转载请注明原文链接:http://blog.zyan.cc/nginx_php_v6/] 前言:本文是我撰写的关于搭建“Nginx ...
- Spring Boot干货系列:(十二)Spring Boot使用单元测试(转)
前言这次来介绍下Spring Boot中对单元测试的整合使用,本篇会通过以下4点来介绍,基本满足日常需求 Service层单元测试 Controller层单元测试 新断言assertThat使用 单元 ...