我有问题。我想创建一个日历,显示下面输入框中点击的日期,但我似乎无法正常工作。
HTML
$("#calendar").datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
});
$(function(){
$('#calendar').datepicker({
onSelect: function(dateText, inst) {
$("input").val(dateText);
}
});
});
的Javascript
{{1}}
任何人都有任何关于我的代码错误的提示。这是我的jsbin以及http://jsbin.com/najunexipe/edit?html,js,output
答案 0 :(得分:2)
这有效:
$("#calendar").datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
onSelect: function(dateText, inst) {
$("input").val(dateText);
}
});
好像你不能两次初始化插件。
答案 1 :(得分:1)
见变化.....
HTML
<!doctype html>
<html>
<head>
<title>Deadline Calculator</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="main.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<input type="text" class="datepicker" id="importantthing" name="importantthing" value="" />
</body>
</html>
的javascript
$(function(){
$('.datepicker').datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
onSelect: function(dateText, inst) {
//$("input").val(dateText);
}
});
});