jQuery确认并退出功能 [英] jquery confirm and exit functionality

查看:346
本文介绍了jQuery确认并退出功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所示的html页面中,将放置window.onbeforeunload = confirmExit代码的位置,以便在显示validate div时,当用户单击取消"或保存"按钮时,以及当用户单击或其他链接时,都不会出现警告消息.应该显示警报消息

In the html page shown,where is window.onbeforeunload = confirmExit code to be placesd so that when validate div is shown the alert message does not appear when the user clicks on cancel or save button.And if the user clicks or any other link the alert message should be shown

如果单击任何其他链接,应调用makeajaxcall()函数,然后继续

If any other link is clicked makeajaxcall() function should be called and then continue

    <div id="start" ></div>
    <div id="validate" >
     <input type="button" /value="cancel" onclick="window.locatcation='cancel()'"> 
     <input type="button" /value="save" onclick="save()">
    </div>
   <div id="confirm" ></div>
  <input type="hidden" name="localchanges" id="localchanges" value="1">


   <script>
 function cancel()
 {
 $('lovalchanges').val('0');
  makeajaxcall();
 }

function makeajxcall()
{
     send request to server and get response 
}


$(document).ready({
 if(load_flag == 2)
{
 $("#validate").css({'display':block});
$("#start").css({'display':none});
 $("#confirm").css({'display':none});
  window.onbeforeunload = confirmExit ;
 }
  });
     function confirmExit()
    {
    var ele = document.getElementById ("localchanges") ;
   if (ele.value == "1")
   return "You have not saved any change made . Discard Changes ?" ;
   }

 </script>

推荐答案

$(document).ready()中,您的语法错误,

您忘记在.ready(function (){ .... });

$(document).ready(function() {
   if(load_flag == 2) {
     $("#validate").css({'display':'block'});
     $("#start").css({'display':'none'});
     $("#confirm").css({'display':'none'});
     window.onbeforeunload = confirmExit ;
   }
});

这篇关于jQuery确认并退出功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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