如何在js / prototype中使用特定的顺序触发事件(onclick) [英] How to trigger events (onclick) with specific orders in js/prototype

查看:776
本文介绍了如何在js / prototype中使用特定的顺序触发事件(onclick)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

用原型触发事件


示例,3个onclick事件在javascript / prototype。如何强制原型运行警报功能转储第一!,第二!然后第三!值。谢谢,这里是你可以c / p的代码:

 < html& 
< head>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js>< / script>
< / head>
< body>
< script type =text / javascript>
//<![CDATA [
document.observe(dom:loaded,function(){
$(go)。 {alert('First!');});
$(go)。 go)。observe(click,function(){alert('Second!');});
});
//]]>
< / script>
< form>
< input id =gotype =buttonvalue =点击我! />
< / form>
< / body>
< / html>


解决方案

事件处理程序是JavaScript中的函数,公民在JavaScript。通常中间对象包含所有处理程序的列表作为数组。例如,在jQuery中, data('events')包含事件处理程序。



p> As @gaby说,你可以使用正确的顺序绑定他们在你的标记在第一。


Possible Duplicate:
Trigger an event with Prototype

example, 3 onclick events in javascript/prototype. How to force prototype to run alert functions for dump "first!", "second!" and then "third!" value. Thanks and here is code that you can c/p:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"></script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function() {
  $("go").observe("click", function() { alert('First!'); });
  $("go").observe("click", function() { alert('Third!'); });
  $("go").observe("click", function() { alert('Second!'); });
  });
//]]>
</script>
<form>
<input id="go" type="button" value="Click me!"  />
</form>
</body>
</html>

解决方案

Event handlers are functions in JavaScript, and functions are prime citizens in JavaScript. Usually a middle object contains the list of all handlers as an array. For example, in jQuery, data('events') holds the event handlers. Unless prototype has an straightforward, you should manually fetch all handlers, order them up and assign them back.

Or

As @gaby has said, you can bind them using correct order in you markup at first place.

这篇关于如何在js / prototype中使用特定的顺序触发事件(onclick)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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