[英]Alternative to Mozilla 'explicitOriginalTarget' for cross browser functionality
I have a fiddle at: http://jsfiddle.net/radi8/Nt556/1/ 我有一个小提琴: http : //jsfiddle.net/radi8/Nt556/1/
This class will bind a listener to all of the 'submit' buttons on a form. 此类将侦听器绑定到窗体上的所有“提交”按钮。 When the user clicks on one of the buttons, the class function will process it as necessary.
当用户单击其中一个按钮时,类功能将根据需要对其进行处理。 I originally developed this class using FireFox and using the: var btnName = event.originalEvent.explicitOriginalTarget.defaultValue;
我最初使用FireFox开发此类并使用:var btnName = event.originalEvent.explicitOriginalTarget.defaultValue; works great therein, but I later found that this is a Mozilla only function.
在这里工作很好,但我后来发现这只是一个Mozilla功能。
Can anyone offer an alternative for IE and Chrome? 任何人都可以为IE和Chrome提供替代品吗?
my class: 我的课:
var RequiredField = {
init: function() {
var theForm = document.getElementsByTagName("form");
$(theForm).bind("submit", RequiredField.submitListener);
},
submitListener: function(event) {
event.preventDefault();
var btnName = event.originalEvent.explicitOriginalTarget.defaultValue;
if (btnName == 'Process Route') {
processType = 0;
alert('Process');
}
else if (btnName == 'Finalize Route') {
processType = 1;
alert('Finalize');
}
else {
processType = 99;
}
try {
}
catch (e) {
event.preventDefault();
}
}
};
RequiredField.init();
I'd just bind "click" for the form: 我只是为表单绑定“click”:
$('form').delegate(':submit', 'click', RequiredField.submitListener);
Then the target of the event will be the button directly. 然后事件的目标将是直接按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.