我想知道如何使用 YUI3 以编程方式触发更改事件——我向一个选择框节点添加了一个更改侦听器:
Y.get('#mynode').on('change', function(e) {
Alert(“changed me”);
});
并且脚本中的其他地方想要触发该事件。当然,当用户更改浏览器中的选择框值时,它会起作用。但是我尝试了很多以编程方式触发它的方法,但都没有奏效。包含:
// All below give this error: T[X] is not a function (referring to what's called in .invoke(), // in the minified javascript
Y.get('#mynode').invoke('onchange');
Y.get('#mynode').invoke('change');
Y.get('#mynode').invoke('on','change');
Y.get('#mynode').invoke("on('change')");
/* Tried using .fire() which I found here:
* http://developer.yahoo.com/yui/3/api/EventTarget.html#method_fire
* Nothing happens
*/
Y.get('#mynode').fire('change');
/* Looking around the APIs some more, I found node-event-simulate.js:
* http://developer.yahoo.com/yui/3/api/node-event-simulate.js.html,
* which by its name would seem to have what I want. I tried:
* Error: simulate(): Event 'change' can't be simulated.
* ( (function(){var I={},B=new Date().getTim...if(B.isObject(G)){if(B.isArray(G)){E=1;\n)
*/
Y.get('#mynode').simulate('change');
任何帮助,将不胜感激!