2017-05-12 11 views
1

jquery datepickerプラグインのminDate()およびmaxDate()プロパティを使用してピッキングを制限する方法を見てきました。日付の値の範囲は、今まで働いたことはありません。どのようにjQuery UIプラグインの公式ページで作業していたサンプルコードでも、私は試しましたが、うまくいきませんでした。私は任意の助けに感謝しますjQuery datepickerプラグインのminDate()およびmaxDate()プロパティが機能しない

$(document).ready(function() { 
    $("#enrolldateprim").datepicker({ 
     minDate: new Date(2009, 10 - 1, 25), 
     maxDate: "now", 
     buttonText: "Select date", 
     dateFormat: 'yy-mm-dd' 
    }); 
}) 

それが動作する前にリンクする別のプラグインがある場合は、これを達成するためにどのようにか...援助を必要としてください。どうもありがとう。知恵

+0

あなたのコード整頓 –

+0

フィドルや実行可能なコードを提供してください私たちは問題を解決できるように..: - ) –

+0

コードに括弧がありません。 – athi

答えて

0

jquery-ui datepicker widgetをお使いの場合は、以下のコードをご覧ください。ところで

は、buttonTextは「ボタン」または「両方」に設定showOnオプションと組み合わせて使用​​する必要がありますので、私はshowOnオプションを追加します。

$(function(){ 
 
    $("#datepicker").datepicker({ 
 
      minDate: new Date(2016, 10 - 1, 25), 
 
      maxDate: "now", 
 
      buttonText: "Select date", 
 
      dateFormat : 'yy-mm-dd', 
 
      showOn: "both" 
 
    }); 
 
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css"> 
 
<script src="//code.jquery.com/jquery-1.12.4.js"></script> 
 
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 

 
<body> 
 
    
 
<p>Date: <input type="text" id="datepicker"></p> 
 

 
</body>

0

下のチェック例:

$(document).ready(function() { 
 
    $("#enrolldateprim").datepicker({ 
 
     minDate: new Date(2017, 5-1 , 5), // months count starts from 0 
 
     maxDate: "now", 
 
     buttonText: "Select date", 
 
     dateFormat: 'yy-mm-dd', 
 
     showOn: "both" 
 
    }); 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/> 
 
<script 
 
    src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" 
 
    integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" 
 
    crossorigin="anonymous"></script> 
 
<input id="enrolldateprim">

あなたは、コードスニペットでは、ライブラリのソースを見つけることができます。

0

あなたはから依存関係をダウンロードすることができます:ちょうど最初のリンクに移動して、あなたがダウンロードボタンが表示されるまでスクロールダウンhttps://jquery.com/download/

:からhttp://jqueryui.com/download/ とjQuery自体。あなたの好みのテーマを選択し、ダウンロードを押してください。 zipファイルを解凍し、リンク(href)とスクリプト(src)で(自分のコード内で)調べて、それを動作させるために何を含めるかを確認します。

もちろん、スタイリング(CSS)を含める必要はありませんが、使用する場合はzipファイルが付属しています。

コード:

<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>jQuery UI Datepicker - Default functionality</title> 
    <link rel="stylesheet" href="jquery-ui-1.12.1.custom/jquery-ui.css"> 
    <link rel="stylesheet" href="jquery-ui-1.12.1.custom/jquery-ui.structure.css"> 
    <link rel="stylesheet" href="jquery-ui-1.12.1.custom/jquery-ui.theme.css"> 
    <script src="jquery-3.1.1.js"></script> 
    <script src="jquery-ui-1.12.1.custom/jquery-ui.js"></script> 
    <script> 
     $(function() { 
     $("#datepicker").datepicker(
      { 
       minDate: new Date(2009, 10 - 1, 25), 
       maxDate: "now", 
       buttonText: "Select date", 
       dateFormat: 'yy-mm-dd', 
       showOn: "both" 
      }); 
     }); 
    </script> 
</head> 
<body> 
    <h3>My DateTimePicker</h3> 
    <p>Pick date: 
     <input type="text" id="datepicker"> 
    </p> 
</body> 
</html> 

PS:

$(function() { 
    // Handler for .ready() called. (This is shorter) 
}); 

は同じ行います

$(document).ready(function() { 
    // Handler for .ready() called. (This is longer) 
}); 
関連する問題