[转]jQuery: how to get which button was clicked upon form submission?
$(document).ready(function() {
$("form").submit(function() {
var val = $("input[type=submit][clicked=true]").val();
// DO WORK
});
$("form input[type=submit]").click(function() {
$("input[type=submit]", $(this).parents("form")).removeAttr("clicked");
$(this).attr("clicked", "true");
});
});
$("form").submit(function() {
// Print the value of the button that was clicked
console.log($(document.activeElement).val());
}
This was helpful, to get the id
of the activeElement
, I did $(document.activeElement).attr('id');
|
For what it's worth, you don't need to use jQuery to get the id - it's even simpler to use pure Javascript:
document.activeElement.id |
[转]jQuery: how to get which button was clicked upon form submission?的更多相关文章
- jQuery和CSS3炫酷button点击波特效
这是一款效果很炫酷的jQuery和CSS3炫酷button点击波特效.该特效当用户在菜单button上点击的时候.从鼠标点击的点開始,会有一道光波以改点为原点向外辐射的动画效果,很绚丽. 在线演示:h ...
- js进阶 12-15 jquery如何实现点击button显示列表,点击其它位置隐藏列表
js进阶 12-15 jquery如何实现点击button显示列表,点击其它位置隐藏列表 一.总结 一句话总结:在button中阻止事件冒泡. 1.如何咋button中阻止事件冒泡(两种方法)? ev ...
- Jquery组织Form表单提交之Form submission canceled because the form is not connected
有时候导出Excel时需要根据某些条件筛选数据,然后将数据通过NPOI生成Excel并导出.组织数据时可以通过放到一个表单中,某些场景是使用脚本(如:jquery)组织一个form(通过字符串拼接), ...
- 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.10.Button 和 Autocomplete控件
Button ,可以使用 <button> <input> <a>. <input> 中的不同类型,submit , radio , checkbox ...
- jquery JavaScript如何监听button事件
下面的html页面中有两个按钮 <div class="layui-tab-item layui-show"> <form class="layui-f ...
- jQuery 分割按钮(Split Button)
代码写多了,有些使用过的方法和技巧会一时半会想不起来,平日记录下来,方便自己和有需要的人日后查阅. <html> <head> <style type="tex ...
- 使用jquery点击一个实现button或连接,进行以下div显示,在点击隐藏
jquery代码: <script type="text/javascript" src="js/jquery-1.7.2.js"></scr ...
- jQuery EasyUI API 中文文档 - 表单(form补充)
继承(表单验证) 第一个参数如果是true那么就算key相同也会接着追加,相反怎会覆盖 $.extend([bool],obj,obj1); var obj = {name:"zhangsa ...
- jQuery file upload --Multiple File Input Fields in One Form
The plugin can be applied to a form with multiple file input fields out of the box. The files are se ...
随机推荐
- VS2012 asp.net mvc 4 运行项目提示:"错误消息 401.2。: 未经授权: 服务器配置导致登录失败"
创建mvc4 应用程序发布,运行出错.出现未经授权: 服务器配置导致登录失败.请验证您是否有权基于您提供的凭,后来找得解决方法: 打开点站的web.confg文件,将: <authorizati ...
- Eclipse 寻找迷失的ID
这一篇会介绍用一种蠢的办法找拓展点常量ID. 1.打开IDE,之后什么都不干,直接关闭IDE,将当前工作区间(workspace)上的文件.metadata\.plugins\org.eclipse. ...
- 由Vue引发的getter和setter思考
公司的新项目决定使用Vue.js来做,当我打印出Vue实例下的data对象里的属性时,发现了一个有趣的事情: 它的每个属性都有两个相对应的get和set方法,我觉的这是多此一举的,于是去网上查了查Vu ...
- SharePoint 2013 WebPart 管理工具分享[开源]
前言 之前做门户的时候,经常要导入导出WebPart,非常的频繁,然后就需要一个个导出,然后一个个导入,非常繁琐:闲暇之际,就考虑能不能自动化一下,把这个功能写成一个工具,可以方便的管理WebPart ...
- SharePoint Server 2016 Update
Today’s post was written by Seth Patton, senior director of product management for the SharePoint te ...
- SharePoint如何关掉mysite. how to disable mysite creation
一个很简单的问题 center admin --> application managment -->manage service application -->user profi ...
- Android Testing学习02 HelloTesting 项目建立与执行
Android Testing学习02 HelloTesting 项目建立与执行 Android测试,分为待测试的项目和测试项目,这两个项目会生成两个独立的apk,但是内部,它们会共享同一个进程. 下 ...
- Ubuntu 16.04 LTS 安装配置 Nginx 1.10.0 Php7.0-FPM
1. 安装Nginx,Php-7.0 ~$ sudo add-apt-repository ppa:nginx/stable ~$ sudo apt-get update ~$ sudo apt-ge ...
- Ubuntu下安装Naginx, PHP5(及PHP-FPM),MySQL
一:安装前做个简单的说明 二:安装MySQL 三:安装Nginx 四:安装PHP5 五:配置 nginx,以下是我本机的配置文件. 六:让MySQL支持PHP5 七:配置PHP-FPM 八:在/etc ...
- UI复习
UIButton的状态 • normal(普通状态) ➢ 默认情况 ➢ 对应的枚举常量:UIControlStateNormal • highlighted(高亮状态) ➢ 按钮被按下去的时候(手指还 ...