2009-02-05 69 views

回答

12

例子:

<script type="text/javascript"> 
    var shouldConfirm = false; 
    window.onbeforeunload = function() { 
     if(shouldConfirm) { 
      return "You have made unsaved changes. Would you still like to leave this page?"; 
     } 
    } 
</script> 

<input id="FullName" type="text" /> 
<script type="text/javascript"> 
    document.getElementById('FullName').onchange = function() { 
     shouldConfirm = true; 
    } 
</script> 

有在4GuysFromRolla.com一个完整的文章。

0

这是它是如何做,但这并不总是可靠:

<html> 
<head> 
<script type="text/javascript"> 
function leaving() 
{ 
    if(confirm("Would you like to save?")) 
    { 
     //Save info 
    } 
    else 
    { 
     //Don't save 
    } 
} 
</script> 
</head> 
<body onUnload="leaving()"> 
<!--Stuff--> 
</body> 
</html> 
相关问题