new Function
と with
を使用するのは悪い習慣ですが、これは次のように行うことができます: http://jsfiddle.net/pimvdb/72GwE/13/ 。
function trigger(elem, name, e) {
var func = new Function('e',
'with(document) {'
+ 'with(this) {'
+ elem.getAttribute('on' + name)
+ '}'
+ '}');
func.call(elem, e);
}
次のHTMLを使用します。
<input type="text" oncustombind="console.log(e, type, getElementById);" id="x">
次のようなイベントをトリガーします:
trigger(document.getElementById('x'), 'custombind', {foo: 123});