YUI 3以编程方式发生火灾事件 [英] YUI 3 programmatically fire change event

查看:133
本文介绍了YUI 3以编程方式发生火灾事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用YUI3以编程方式触发更改事件 - 我向一个选择框节点添加了一个更改侦听器:

  Y.get('#mynode')。on('change',function(e){
Alert(changed me);
});

并且脚本中的其他地方想要触发该事件。当然,当用户更改浏览器中的选择框值时,它起作用。但是我已经尝试了许多方法来以编程方式启动它们,其中没有一个有效。包括:

  //所有下面给出了这个错误:T [X]不是一个函数(指的是在.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') );


/ *尝试使用.fire(),我在这里找到:
* http://developer.yahoo.com/yui/3/api/EventTarget。 html#method_fire
*没有任何事情
* /

Y.get('#mynode')。fire('change');

/ *再来看一下API,我发现了node-event-simulate.js:
* http://developer.yahoo.com/yui/3/api/node-event-simulate.js.html,$
*错误:simulate():事件'change'不能被模拟
*((function() {var I = {},B = new Date()。getTim ... if(B.isObject(G)){if(B.isArray(G)){E = 1; \\\

* /

Y.get('#mynode')。simulate('change');

任何帮助将不胜感激!

解决方案

YUI 3.0不支持模拟更改事件,如你所发现的。但是,它将在YUI 3.1中得到支持。现在中继线



您的第三个尝试:

  Y.get('#mynode')。simulate('change'); 

应该在3.1中工作。



编辑



看起来你可以替换YUI 3.0版本的 event-simulate.js 与trunk版本,它将工作在另一个3.0应用程序。迄今为止我还没有看到任何问题。


I was wondering how to programmatically fire a change event with YUI3 -- I added a change listener to one select box node:

Y.get('#mynode').on('change', function(e) {
 Alert("changed me");
});

and somewhere else in the script want to fire that event. It works, of course, when a user changes the select box value in the browser. But I've tried many ways to fire it programmatically, none of which have worked. Including:

// 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');

Any help would be appreciated!

解决方案

YUI 3.0 does not support simulating the change events, as you've discovered. However it will be supported in YUI 3.1. It is in the trunk now.

Your third attempt:

Y.get('#mynode').simulate('change');

should work in 3.1.

edit

It looks like you can just replace the YUI 3.0 version of event-simulate.js with the trunk version, and it will work in an otherwise 3.0 app. I haven't seen any issues so far.

这篇关于YUI 3以编程方式发生火灾事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆