问题:存在3个页面,假设它们分别被称为first,second,third。在first页面中有“保存”按钮,当用户点击“保存”按钮后,再点击second或者third的链接,此时直接跳转;当用户忘记点击“保存”按钮时,去点击second或者third的链接,就会弹出confirm()警告框,询问用户是否“保存”,用户点击“确定”,就先保存再跳转,用户点击“取消”就直接跳转。
 请赐教!谢谢。

解决方案 »

  1.   

    <script>
    var saved = false;
    var nextPageUrl;
    function save(){
    // save data    code here}
    function cfmSave(){
    if (saved===true) {
    return true;
    }
    else
    {
    if(confirm("notice here")){
    save();
    return true;
    }
    else
    {
    return true;
    }

    }
    }
    function nextStep(url){
    nextPageUrl = url;
    if(cfmSave()){
    window.location= url;  // location next page
    }
    }so easy