开发者

jquery confirm and exit functionality

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

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>


In $(document).ready(), your syntax is wrong,

you forgot to write function() in .ready(function (){ .... });

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜