2016-11-16 77 views
0

我的代碼是:停止的jQuery UI的日期選擇器的確認框

HTML,

Date : <input id="datepicker"> 
Fare : <input id="fare"> 

JS,

<script> 
    $(function(){ 
     $("#datepicker").datepicker({ 
      changeMonth: true, 
      changeYear: true, 
      showAnim: 'clip', 
      dateFormat: "yy-mm-dd" 
     }).val(); 
    }); 


    $("#datepicker").click(function() { 
     if (confirm("If you change the Date the Fare fields data will be deleted !!")) { 
      $('#fare').val(''); 
     } else { 
      return false; 
      $("#datepicker").datepicker('destroy'); 
     } 
    }); 
<script> 

我想,當我取消停止日期選擇器確認框。不幸的是它不工作。請幫助。

回答

0

您返回false然後銷燬日期選擇器。

它應該是相反的。試試這個:

$("#datepicker").click(function() { 
    if (confirm("If you change the Date the Fare fields data will be deleted !!")) { 

     $('#fare').val(''); 

    }else{ 
     $("#datepicker").datepicker('destroy'); 
     return false; 
    } 
}); 
0

首先,摧毀然後做return false

<script> 
$(function(){ 
    $("#datepicker").datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     showAnim: 'clip', 
     dateFormat: "yy-mm-dd" 
    }).val(); 
}); 


$("#datepicker").click(function() { 
    if (confirm("If you change the Date the Fare fields data will be deleted !!")) { 
     $('#fare').val(''); 
    }else{ 
     $("#datepicker").datepicker('destroy'); 
     return false; 
    } 
});