如何使用 Jquery 在不同的 div 中显示月份选择器
How to display the monthpicker in diferent div using Jquery
我需要在一个不同的 div 中显示月份选择器 UI 但所选值将使用 Jquery 获取到输入字段.我在下面解释我的代码。
<!DOCTYPE html>
<html>
<head>
<title>Parent-Child Communication</title>
<link rel="stylesheet" type="text/css" href="jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" href="monthpicker.css" />
<script src="jquery-2.2.3.min.js"></script>
<script src="jquery-ui.min.js"></script>
<script src="monthpicker.min.js"></script>
</head>
<body>
<input id="sDate" type="text" />
<div id="packagetour_datepickerpick"></div>
<script type="text/javascript">
$('#sDate').Monthpicker();
</script>
</body>
</html>
这里我需要在 <div id="packagetour_datepickerpick"></div>
中显示月份选择器,但所选值应该提取到输入字段。 (这里是演示代码
)[http://plnkr.co/edit/vtth4dTXTUapFfFQB8MC?p=preview].
注:如评论区所述
我创建了一个 运行 使用以下库的示例。
- https://code.jquery.com/jquery-1.9.1.js
- https://code.jquery.com/ui/1.9.2/jquery-ui.js
- https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css
- https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.css
- https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.js
$("#packagetour_datepickerpick").MonthPicker({
SelectedMonth: '04/' + new Date().getFullYear(),
AltField: '#sDate',
OnAfterChooseMonth: function(selectedDate) {
// Do something with selected JavaScript date.
// console.log(selectedDate);
}
});
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css" rel="stylesheet"/>
<link href="https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.css" rel="stylesheet"/>
<script src="https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.js"></script>
<input id="sDate" type="text" />
<div id="packagetour_datepickerpick"></div>
希望对您有所帮助。 :)
我需要在一个不同的 div 中显示月份选择器 UI 但所选值将使用 Jquery 获取到输入字段.我在下面解释我的代码。
<!DOCTYPE html>
<html>
<head>
<title>Parent-Child Communication</title>
<link rel="stylesheet" type="text/css" href="jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" href="monthpicker.css" />
<script src="jquery-2.2.3.min.js"></script>
<script src="jquery-ui.min.js"></script>
<script src="monthpicker.min.js"></script>
</head>
<body>
<input id="sDate" type="text" />
<div id="packagetour_datepickerpick"></div>
<script type="text/javascript">
$('#sDate').Monthpicker();
</script>
</body>
</html>
这里我需要在 <div id="packagetour_datepickerpick"></div>
中显示月份选择器,但所选值应该提取到输入字段。 (这里是演示代码
)[http://plnkr.co/edit/vtth4dTXTUapFfFQB8MC?p=preview].
注:如评论区所述
我创建了一个 运行 使用以下库的示例。
- https://code.jquery.com/jquery-1.9.1.js
- https://code.jquery.com/ui/1.9.2/jquery-ui.js
- https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css
- https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.css
- https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.js
$("#packagetour_datepickerpick").MonthPicker({
SelectedMonth: '04/' + new Date().getFullYear(),
AltField: '#sDate',
OnAfterChooseMonth: function(selectedDate) {
// Do something with selected JavaScript date.
// console.log(selectedDate);
}
});
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css" rel="stylesheet"/>
<link href="https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.css" rel="stylesheet"/>
<script src="https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.js"></script>
<input id="sDate" type="text" />
<div id="packagetour_datepickerpick"></div>
希望对您有所帮助。 :)