我想要一個函數來檢查字段中的日期是否從今天的日期過去超過50年。如果過去的日期超過50年,應該顯示一條消息,但不應該有最短的日期(最長年份)。檢查字段中的日期是否大於x
我有一個可以動態添加更多字段的表單(名稱+出生日期),如果過去的時間超過50年,每個新的「表單」都應該在生日字段下顯示此消息。
每出生日期場下的警告信息應該是這樣的(如果超過50):
<div class="alert alert-warning">This person is over 50 year. Remember to do...</div>
我的HTML設置:
<label for="id_nested-0-name">Name</label>
<input id="id_nested-0-name" maxlength="200" name="nested-0-name" type="text" />
<label for="id_nested-0-birthdate">Birthdate</label>
<input class="dateinput" datadatepicker="datepicker" id="id_nested-0-birthdate" name="nested-0-birthdate" type="date" />
<!-- If nested-0-birthdate is over 50, add html with warning message -->
<!-- New person -->
<label for="id_nested-1-name">Name</label>
<input id="id_nested-1-name" maxlength="200" name="nested-1-name" type="text" />
<label for="id_nested-1-birthdate">Birthdate</label>
<input class="dateinput" datadatepicker="datepicker" id="id_nested-1-birthdate" name="nested-1-birthdate" type="date" />
<!-- If nested-1-birthdate is over 50, add html with warning message -->
編輯:
此代碼在鉻合金中效果很好,但在Safari中不起作用。任何人都可以看到什麼可能是錯的我的日期選擇器使用http://eonasdan.github.io/bootstrap-datetimepicker/。
編輯2:
我錯過了我的輸入data-format="DD/MM/YYYY"
。現在一切正常!
爲什麼不使用' '? –
它不應該是任何最短日期,只是一個「警告」,如果該人超過50歲。 –
呃,夠公平的。還有,''是非常有用的^ _^ –