当选择日期时,我必须调用 JavaScript 函数,JavaScript 如下,
$(document).ready(function(){
var date_input=$('input[name="date"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
date_input.datepicker({
format: 'yyyy-mm-dd',
container: container,
todayHighlight: true,
autoclose: true,
onSelect: function (dateText, inst) {
getdsr(dateText);
}
})
})
日期的 html 如下,
<input id="txtdate" class="form-control" name="date" placeholder="YYYY/MM/DD" type="text" required>
由于某种原因,onselect 不起作用。
最佳答案
$(document).ready(function(){
var date_input=$('#txtdate'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
$('#txtdate').datepicker({
format: 'yyyy-mm-dd',
container: container,
todayHighlight: true,
autoclose: true,
onSelect: function (dateText, inst) {
//getdsr(dateText);
console.log(dateText);
}
})
})
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input id="txtdate" class="form-control" name="date" placeholder="YYYY/MM/DD" type="text" required/>
关于javascript - 日期选择器上的 onSelect 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42852147/