[英]event.type undefined in firefox
I have the following function: 我有以下功能:
format : function(element,p){
//function body
if(event.type == 'focus'){
//execute this condition only on focus event
}
}
that is being called on the focus event and on page load. 在焦点事件和页面加载时被调用。 element is the input element's value and p is an optional arguement, I want to execute the if only on the focus on the input element.
element是输入元素的值,p是可选的论据,我想仅在关注输入元素时执行if。 If I simply apply event.type == 'focus', it works for IE and chrome, but for firefox it says event is not defined.
如果我简单地应用event.type =='focus',它适用于IE和chrome,但对于firefox,它表示未定义事件。
Does anyone have a workaround for this? 有人对此有解决方法吗? Thanks in advance.
提前致谢。
var myObj = {
format: function (event) {
// passing in the event object should give you everything you need:
// event.type (the event's type)
// event.target (the element which the event was fired on)
// event.which (in the case of keyboard events, this is the key that was pressed)
// see mdn dox @ https://developer.mozilla.org/en-US/docs/Web/API/Event
if (event.type === 'focus') {
// execute focus code
}
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.