行动的执行顺序 [英] execution order of actions

查看:78
本文介绍了行动的执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想为一个活动做两个动作。但我希望在第一个动作完成时触发第二个

动作。在javascript中这样做是否可以

?我正在使用onclick活动。


谢谢,

罗马

解决方案



roman写道:



我想对一个事件有两个动作。但我想在第一个动作完成时触发第二个动作。是否可以在javascript中执行此操作?我正在使用onclick活动。

谢谢,
罗马




当然可以。 :)例如:


elem.onclick = function()

{

myfunc_act1();

myfunc_act2();

}


只要第一个函数不是异步的,它就会执行
$ b提供的订单是$ b。


窗口弹出窗口是否会计算异步操作?


我是试图在一个事件中组合两个动作 - > onclick。


Action1 - > popupwindow1;选择一些东西带回父母表格;

Action2 - > popupwindow2;做某事并显示信息;点击

窗口关闭;


这可能吗?现在我有两个按钮,用户需要点击两个按钮。我想把它们结合起来。


谢谢,

罗马


罗马




roman写道:



我想一个人有两个动作事件。但我想在第一个动作完成时触发第二个动作。是否可以在javascript中执行此操作?我正在使用onclick活动。

谢谢,
Roman




JavaScript本身并没有同步方法。多个函数

对同一事件的调用只是被添加到事件处理程序的

内部哈希,而不保证执行顺序。

Say(Gesko syntacs):

obj.addEventListener(''click'',f1,false);

obj.addEventListener(''click'',f2 ,false);

并不意味着在点击功能的情况下f1()将首先调用
,然后调用函数f2()秒(它可能发生在对面)。

此外没有内置的方法来确保f2()在f1()完成之前不会启动




有不同的技巧可以模拟< synchronized>行为在

JavaScript中。最简单的方法(虽然并不总是适用)是

将函数的返回值赋给某些虚假变量:

....

var foo = f1(); //伪同步函数

foo = f2(); //伪同步函数

....

f1()或f2()没有返回值无关紧要(所以< foo>会

设置为undefined)。该程序仍将等待该未定义的

值,直到该函数退出 - 这非常接近

同步行为。


Hi,

I would like to have two actions for one event. But I want the second
action to trigger when the first one action completes. Is it possible
to do this in javascript? I''m using the onclick event.

Thanks,
Roman

解决方案


roman wrote:

Hi,

I would like to have two actions for one event. But I want the second
action to trigger when the first one action completes. Is it possible
to do this in javascript? I''m using the onclick event.

Thanks,
Roman



Sure it is. :) For example:

elem.onclick = function ()
{
myfunc_act1();
myfunc_act2();
}

As long as the first function isn''t asynchronous, then it will execute
in the order provided.


Would a window popup count a an asynchronous action?

I am trying to combine two actions in one event -> onclick.

Action1 -> popupwindow1; select something; bring back to parent form;
Action2 -> popupwindow2; does something and displays message; click on
window close;

Is this possible? Right now I have two buttons and the users need to
click on both. I would like to combine them.

Thanks,
Roman

Roman



roman wrote:

Hi,

I would like to have two actions for one event. But I want the second
action to trigger when the first one action completes. Is it possible
to do this in javascript? I''m using the onclick event.

Thanks,
Roman



JavaScript doesn''t have synchronized methods per se. Multiple function
calls on the same event are just being added to the event handler''s
internal hash without any guarantee of an execution order.
Say (Gesko syntacs):
obj.addEventListener(''click'',f1,false);
obj.addEventListener(''click'',f2,false);
doesn''t mean at all that in case of a click function f1() will be
called first and function f2() second (it may happen just opposite).
Also there is no a build-in way to ensure that f2() will not start
until f1() is finished.

There are different tricks to emulate the <synchronized> behavior in
JavaScript. The most simple one (though not always applicable) way is
to assign the function''s return value to some bogus variable:
....
var foo = f1(); // pseudo-synchronized function
foo = f2(); // pseudo-synchronized function
....
It does not matter if f1() or f2() have no return value (so <foo> will
be set to undefined). The program will still wait for that undefined
value until the function exits - which is pretty close to the
synchronized behavior.


这篇关于行动的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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