[英]Get clicked element with Jquery on Safari
I'm trying to get the input element clicked on a form. 我正在尝试在表单上单击输入元素。 I've two input type submit : one to save the form and the other to validate it.
我有两种输入类型Submit:一种用于保存表单,另一种用于验证表单。 I need to know which button was clicked.
我需要知道单击了哪个按钮。
It's work for all browsers except Safari. 它适用于除Safari之外的所有浏览器。
JS : JS:
var target = e.originalEvent.explicitOriginalTarget || e.relatedTarget || document.activeElement;
var buttonId = $(target).id;
if (buttonId == "opSave") {
//doSomething
} else if (buttonId == "opCreate") {
//doSomething
}
HTML : HTML:
<input type='submit' onclick="void(0)" id="opSave" name='opSave' value='Save' />
<input type='submit' onclick="void(0)" id="opCreate" name='opCreate' value='Submit' />
Can you please go with JQuery approach of attaching click event like follows: 能否请您使用附加单击事件的JQuery方法,如下所示:
HTML: HTML:
<input type='submit' onclick="void(0)" id="opSave" name='opSave' value='Save' />
<input type='submit' onclick="void(0)" id="opCreate" name='opCreate' value='Submit' />
JQuery: JQuery的:
$(document).ready(function(){
$("#opSave").click(function(){
//doSomething
});
$("#opCreate").click(function(){
//doSomething
});
});
by this way you really don't have to bother about OS and browser 通过这种方式,您真的不必担心操作系统和浏览器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.