2

我正在处理由“更改”事件侦听器激活的长prototype.js 代码,我需要创建一个模拟“更改”事件以激活原型脚本的 jQuery 函数。我怎样才能做到这一点?

注意:$('select[id="..."]').val(...).trigger('change');不激活原型脚本

4

1 回答 1

1

jQuery's .trigger() only works for event handlers added via jQuery (see: http://api.jquery.com/trigger/)

Any event handlers attached with .on() or one of its shortcut methods are triggered when the corresponding event occurs. They can be fired manually, however, with the .trigger() method.

Prototype's .fire() only works for custom events (see: http://api.prototypejs.org/dom/Event/fire/)

Fires a custom event of name eventName with element as its target. Custom events must include a colon (:) in their names.

Unfortunately, the only way to do what you're describing is to grab some kind of reference to the "long prototype.js code" and manually call it. (This would depend on what the implementation you are referring to looks like.) It's not possible to fire a true "native" change event using javascript.

于 2013-02-02T07:10:29.623 回答