亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to modify the return value of js function?
ringa_lee
ringa_lee 2017-05-19 10:11:24
0
5
730
Now we need to encapsulate the pop-up layer into a component. The pop-up layer component contains two operation functions: "cancel" and "confirm", and the return values ??are false and true respectively. How is the return value of this component determined by the return values ??of these two operations?

code show as below:

 function tips(){
    //調(diào)用函數(shù)時(shí),顯示彈出層
    $('.mask').show();
    
    //取消
    $('.cancel').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        return false;
    });
    
    //確定
    $('.confirm').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        return true;
    });
}

I want to call it like this:

if( tips() ){
    do_something_true...
}else{
    do_something_false...
}
Thanks
ringa_lee
ringa_lee

ringa_lee

reply all(5)
淡淡煙草味
function tips(cb){
    //調(diào)用函數(shù)時(shí),顯示彈出層
    $('.mask').show();
    
    //取消
    $('.cancel').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        cb(false);
    });
    
    //確定
    $('.confirm').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        cb(true);
    });
}

tips(function(ret){
  if(ret) {
     // blabla
  } else {
    // blabal
  }
});

If you want to show off your skills, you can do it in ES7:

function tips(){
  return new Promise(resolve => {
    //調(diào)用函數(shù)時(shí),顯示彈出層
    $('.mask').show();
    
    //取消
    $('.cancel').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        resolve(false);
    });
    
    //確定
    $('.confirm').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        resolve(true);
    });
  });
}

async function test() {
  if( await tips()) {
    // do_something_when_true...
  } else {
    // do_something_when_false
  }
  // 是不是熟悉的味道?Promsie是個(gè)好東西,async/await更是
}
大家講道理
function tips(confirmCallback, cancelCallback){
    //調(diào)用函數(shù)時(shí),顯示彈出層
    $('.mask').show();
    
    //取消
    $('.cancel').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        cancelCallback && cancelCallback();
        return false;
    });
    
    //確定
    $('.confirm').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        confirmCallback && confirmCallback();
        return true;
    });
}
左手右手慢動(dòng)作

Add a flag. Flag can also be represented by numbers like 0 and 1.

function tips(){
    var flag = false;
    //調(diào)用函數(shù)時(shí),顯示彈出層
    $('.mask').show();
    
    //取消
    $('.cancel').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        flag = false;
    });
    
    //確定
    $('.confirm').on('click',function(){
        $('.mask').hide();    //隱藏彈出層
        flag = true;
    });
    return flag;
}
曾經(jīng)蠟筆沒有小新

I just learned a very stupid method
var tips_vla="";
function tips(){

//調(diào)用函數(shù)時(shí),顯示彈出層
$('.mask').show();
//取消
$('.cancel').on('click',function(){
    $('.mask').hide();    //隱藏彈出層
    tips_vla=0;
    al(tips_vla);
})
//確定
$('.confirm').on('click',function(){
    $('.mask').hide();    //隱藏彈出層
    tips_vla=1;
    al(tips_vla);
});

}
tips();
function al(){
if(tips_vla){

alert("你點(diǎn)擊了確認(rèn)");

}else{

  alert("你點(diǎn)擊了取消");

}
}

滿天的星座

The laziest way is to add an exclamation mark, hee hee hee

if( !tips() ){
    do_something_true...
}else{
    do_something_false...
}

Of course, it is best to write a sentence in the tips() function, return true

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template