我有以下功能:
format : function(element,p){
//function body
if(event.type == 'focus'){
//execute this condition only on focus event
}
}
正在焦点事件和页面加载上调用。 element是输入元素的值,p是可选的参数,我想只在重点放在input元素上执行if。如果我只是应用event.type =='focus',它适用于IE和chrome,但对于firefox,它表示事件未定义。
有没有人有解决方法?提前谢谢。
答案 0 :(得分:0)
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
}
}
};