The proper way to trigger an event with plain JavaScript, would be to create an Event object, and dispatch it(用纯JavaScript触发事件的正确方法是创建一个Event对象,然后分派它)
var event = new Event('input', {
bubbles: true,
cancelable: true,
});
element.dispatchEvent(event);
FIDDLE(小提琴)
This is not supported in IE, for that the old-fashioned way still has to be used(IE不支持此功能,因为仍然必须使用老式方法)
var event = document.createEvent('Event');
event.initEvent('input', true, true);
elem.dispatchEvent(event);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…