2016-01-04 46 views
-1

Here is my Interface, and i wanted the user to input only the date of his birth這是我的代碼。我想禁用未來日期和我的「出生日期」字段的當前日期禁用未來日期和當前日期

<div class="form-group"> 
           <label class="control-label" 
            for="personal_information.date_of_birth">Date of Birth</label> 
           <input class="form-control" 
            rv-value="data.personal_information.date_of_birth" 
            name="dateOfBirth" id="dateOfBirth" data-validate="required" 
            data-mask="yyyy-mm-dd" placeholder="Pre-formatted birth date" /> 
          </div> 
+0

禁用日期從哪裏? – Lal

+0

好的,真的不明白這個問題......以爲你有多個字段,如果這樣'禁用'會這樣做 – BeNice

+0

@OldMauiMan,但你仍然回答.. – Lal

回答

0

您不能用純HTML或CSS來做到這一點。 JavaScript是必需的。然而,有一個快速的方法來做到這一點,使用兩個JavaScript庫稱爲jQueryjQueryUI

jsFiddle Demo

HTML:

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 

<div id="MyDIV"> 
    Birthday: <input id="bday" type="text" /> 
</div> 

使用Javascript/jQuery的:

$("#bday").datepicker({ 
    maxDate: "-1" 
}); 

注意,您可以使用:

maxDate: "-20Y" 

,以確保出生日期必須至少20歲。


如果您不能確定在何處放置的JavaScript代碼,你可以用你的HTML包括它,<script>標籤之間(在技術上,如果你粘在身上它,它會工作,但實際上它應該去在<head>):

<head> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 

    <script type="text/javascript"> 
     $(document).ready(function(){ 
      $("#bday").datepicker({ 
       maxDate: "-1" 
      }); 
     }); 
    </script> 
</head> 
<body> 

<div id="MyDIV"> 
    Birthday: <input id="bday" type="text" /> 
</div> 

</body> 
+0

夥計。有可能在輸入類型中只使用彈出式日曆嗎? –

相關問題