2015-02-07 44 views
1

下面的腳本執行某些檢查。設計一個jquery確認框

如果用戶嘗試預訂時間少於四小時,會發出警告,建議用戶至少需要四小時。

如果用戶嘗試預訂時間超過四小時,則再次建議用戶在最初四小時後的任何額外小時內可能累積額外費用。

然後向用戶呈現確認框以單擊確定繼續或取消以在四小時內停留。

一切都很好。

但是,我們希望使確認框更吸引眼球。

任何想法如何做到這一點?

這是我的整個工作腳本,並提前致謝。

<script type="text/javascript"> 
      $(window).load(function() { 
       $("#txtFromDate").datepicker(); 
       $('#timeStart').timepicker({ showPeriod: true, 
        onHourShow: OnHourShowCallback, 
        onMinuteShow: OnMinuteShowCallback 
       }); 

       $("#txtToDate").datepicker(); 
       $('#timeEnd').timepicker({ showPeriod: true, 
        onHourShow: OnHourShowCallback, 
        onMinuteShow: OnMinuteShowCallback 
       }); 
       function OnHourShowCallback(hour) { 
        if ((hour > 20) || (hour < 6)) { 
         return false; // not valid 
        } 
        return true; // valid 
       } 
       function OnMinuteShowCallback(hour, minute) { 
        if ((hour == 20) && (minute >= 30)) { return false; } // not valid 
        if ((hour == 6) && (minute < 30)) { return false; } // not valid 
        return true; // valid 
       } 
       $('#btnSearch').on('click', function() { 
        var sDate = $("#txtFromDate").val(); 
        var sTime = $("#timeStart").val(); 

        var eDate = $("#txtToDate").val(); 
        var eTime = $("#timeEnd").val(); 

        var startDate = new Date(sDate + " " + sTime).getHours(); 
        var endDate = new Date(eDate + " " + eTime).getHours(); 

        //Calulate the time difference 
        var hourDiff = endDate - startDate; 
        //alert(hourDiff); 

        //Check if hour difference is less than 4 hours and show the message accordingly 
        if (hourDiff < 4) { 
         alert("A mininum of 4 hours is required!"); 
         return false; 
        } 
        //Here you add the check condition if you are above the 4 hours time frame 
        //Add the check condition if the user is above the 4 hours time frame 
        if (hourDiff > 4) { 
         var r = confirm("There may be additional fees for going over the 4 hours!"); 
         if (r == true) { // pressed OK 
          return true; 
         } else { // pressed Cancel 
          return false; 
         } 
        } 
       }); 
      }); 
     </script> 
+1

['confirm'](https://developer.mozilla.org/en-US/docs/Web/API/Window.confirm)不是jQuery,它不能被設置樣式。你將不得不使用類似jQuery UI對話框的東西。 – 2015-02-07 00:20:23

+1

'r = false; 。 $($(」

There may be additional fees for going over the 4 hours!
「))對話框({ closeOnEscape:假的, \t \t可調整大小:假的, 模式:真, 開:函數(事件,UI){$(」 UI-對話框的標題欄。 -close「)隱藏();}, \t \t按鈕:{ 」OK「:函數(){ \t \t \t R =真; $(本).dialog( 」親密「);} , 取消:function(){ \t \t \t r = false; $(this).dialog(「關」 ); } }, \t \t密切:函數(){ \t \t \t \t返回R等 \t \t \t} });' – billynoah 2015-02-07 00:44:05

+0

你可以這樣做,我可以給你的解決方案信貸? – Tairoc 2015-02-07 00:58:19

回答