javascript确认功能确定并取消返回相同的结果 [英] javascript confirm function ok and cancel return same result

查看:56
本文介绍了javascript确认功能确定并取消返回相同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我正在调用 confirm(param1,param2)方法来显示警告你想继续吗?

Here, I am calling confirm(param1, param2) method to display an alert Do you want to continue?

在这种情况下,如果用户点击确定,则返回 true ,如果用户点击取消,则返回 false

In this case, if the user clicks OK, it returns true, if the user clicks Cancel, it returns false.

但是,当点击取消按钮时,它正在调用 checkcount()方法。

But, when Cancel button is clicked, it is calling checkcount() method.

我的要求是每当用户点击确定按钮时,它应该调用 checkcount( )方法。

My requirement is whenever the user clicks on OK button, it should call checkcount() method.

如何实现这一目标?

<script>
function call(param1, param2, param3)
{
    if (condition)
    {
       /*some process */
    }
    else
    {
       confirm(param1, param2);
       checkcount();
    }
}

function confirm(param1, param2)
{
    if(condition)
    {
       var retVal = confirm("Do you want to continue ?");
       if (retVal == true)
       {
           alert("User wants to continue!");
           return true;
       } 
      else
      {
           alert("User does not want to continue!");
           return false;
      }
   }
}
</script> 


推荐答案

没有支票!

confirm(param1, param2);
checkcount();

并且您希望将功能名称更改为除确认之外的其他名称。

and you want to change your function name to something other than confirm.

<script>
function call(param1, param2, param3)
{
    if (condition)
    {
       /*some process */
    }
    else
    {
        if(myConfirm(param1, param2)) {
            checkcount();
        }
    }
}

function myConfirm(param1, param2)
{
    if(condition)
    {
       var retVal = confirm("Do you want to continue ?");
       if (retVal == true)
       {
           alert("User wants to continue!");
           return true;
       } 
      else
      {
           alert("User does not want to continue!");
           return false;
      }
   }
}
</script> 

这篇关于javascript确认功能确定并取消返回相同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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