如何在js / prototype中使用特定的顺序触发事件(onclick) [英] How to trigger events (onclick) with specific orders in js/prototype
问题描述
可能重复:
用原型触发事件
示例,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屋!