简体   繁体   中英

javascript wait return function into onclick

We have this code (using DHTMLX and 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.

Now my code always check my checkbox and then show the confirm popup.

You can't make JavaScript block on asynchronous functions.

Have your event handler always return false.

Then trigger its functionality inside the callback instead of trying to return true.

You cannot return anything to attachEvent callback. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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