[转]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 ...
随机推荐
- The template engine
Play has an efficient templating system which allows to dynamically generate HTML, XML, JSON or any ...
- 2013年最新流行的响应式 WordPress 主题【下篇】
在这篇文章中,我们收集了一些在2013年发布的最好的免费的响应式 WordPress 主题.这些主题包括高级功能,如自定义模板.自定义窗口小部件.自定义菜单主题选项等.让我们来看看下面的清单,并希望你 ...
- go语言 类型:数组切片
初看起来,数组切片就像一个指向数组的指针,实际上它拥有自己的数据结构,而不仅仅是个指针.数组切片的数据结构可以抽象为以下3个变量: 1.一个指向原生数组的指针: 2.数组切片中的元素个数: 3.数组切 ...
- float 和 inline-block的心得
float 优点: 横向排列时比较方便,不存在浏览器兼容问题. 缺点: 1)多行横向排行时,换行后经常不能顶行显示. 2)浮动后会跳出当前流,造成父元素高度塌陷,解决办法比较成熟统一 ,不存在浏览器兼 ...
- linux下的服务器搭建集成环境
linux下的服务器搭建集成环境 ——写给初学者的我们 1.准备工具 1.1 SecureCRT SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简单地说是Windows下登录 ...
- Android Animation学习(一) Property Animation原理介绍和API简介
Android Animation学习(一) Property Animation介绍 Android Animation Android framework提供了两种动画系统: property a ...
- objective-c系列-NSMutableString
********************************************** NSMutableString为NSString的子类,除了父类的方法,NSMutableStirng还有 ...
- static和extern对函数的作用
- 利用grep命令查找文件内容
例如查找PHP源码某个函数的具体实现 grep -rn "PHP_FUNCTION(socket_accept)" ./ext
- 【转】JavaScript 异步进化史
前言 JS 中最基础的异步调用方式是 callback,它将回调函数 callback 传给异步 API,由浏览器或 Node 在异步完成后,通知 JS 引擎调用 callback.对于简单的异步操作 ...