简体   繁体   English

javascript等待返回函数转换为onclick

[英]javascript wait return function into onclick

We have this code (using DHTMLX and DHTMLXMESSAGE): 我们有以下代码(使用DHTMLX和DHTMLXMESSAGE):

myCheckBox.attachEvent('onEditCell', function(stage,rId,cInd,nValue,oValue){
        dhtmlx.confirm({
            type:"confirm",
            text: "Are you sure?",
            callback: function(result){
                if(result) {
                    return true;
                } 
                return false;
            }
        });
}); 

OnEditCell event should return "true" or "false" to validate action. OnEditCell事件应返回“ true”或“ false”以验证操作。

Now my code always check my checkbox and then show the confirm popup. 现在,我的代码始终选中我的复选框,然后显示确认弹出窗口。

You can't make JavaScript block on asynchronous functions. 您不能在异步函数上使JavaScript阻塞。

Have your event handler always return false. 让事件处理程序始终返回false。

Then trigger its functionality inside the callback instead of trying to return true. 然后在回调中触发其功能,而不是尝试返回true。

You cannot return anything to attachEvent callback. 您无法将任何内容返回给attachEvent回调。 Based on the result of your confirm checkbox, execute the relevant code 根据您的确认复选框的结果,执行相关代码

> callback: function(result){
>                 if(result) {
>                    //don't returnfrom here
                      // execute your code here only.
>                 } 
>                 

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM