IE兼容问题

1、IE下event事件没有target属性,只有srcElement属性,解决方法:使用srcObj = event.srcElement ? event.srcElement : event.target;

 srcObject =event.target||event.srcElement.

JavaScript的特性:2||3=2

 

2、Document.creareEvent()

Creates an event of the type specified. The returned object should be first initialized and can then be passed to element.dispatchEvent.

event.initEvent(type, bubbles, cancelable);

type:is a DOMString defining the type of event

bubbles:is a Boolean deciding whether the event should bubble up through the event chain or not. Once set, the read-only property Event.bubbles will give its value.

cancelable:is a Boolean defining whether the event can be canceled.Once set, the read-only property Event.cancelable will give its value.

example:

// Create the event.
var event = document.createEvent('Event');

// Define that the event name is 'build'.
event.initEvent('build', true, true);

// Listen for the event.
elem.addEventListener('build', function (e) {
  // e.target matches elem
}, false);

// target can be any Element or other EventTarget.
elem.dispatchEvent(event);

 

3、fireEvent method

Fires a special evnet on the object

 

posted on 2016-12-09 10:40  yuliann  阅读(121)  评论(0编辑  收藏  举报

导航