隐藏jQuery日期选择器
Hiding the jQuery datepicker
我想在点击一个小图像时呈现一个日期选择器,选择日期,使用所选日期根据所选日期填充一组年、月和天的选择元素。我计算出了onSelect部分,并将所选日期应用于select元素中的选项。
我的问题是日期选择器在选择日期时没有关闭。它停留在那里。如果我调用hide()方法,它也会隐藏图像(span元素的一部分)。这是我的HTML代码:
<span id="pickupCalendar"><img src="/images/calendar.png"></img></span>
这是脚本:
$("#pickupCalendar").click(function () {
$("#pickupCalendar").datepicker({
dateFormat: 'dd-mm-yy',
onSelect: function (dateText, inst) {
//code to fill the other elements with the selected date goes here
$("#pickupCalendar").datepicker().hide(); //<-- hides the image (span element along with the datepicker)
}
});
});
我会更改HTML标记,这样可以更容易地定位元素。
<span id="pickupCalendar"></span><button>Button</button>
$("button").click(function () {
$("#pickupCalendar").show();
$("#pickupCalendar").datepicker({
dateFormat: 'dd-mm-yy',
onSelect: function (dateText, inst) {
//code to fill the other elements with the selected date goes here
$("#pickupCalendar").datepicker().hide();
}
});
});
FIDDLE
你能试试这个吗?
$("#pickupCalendar").click(function () {
$("#pickupCalendar").datepicker({
dateFormat: 'dd-mm-yy',
onSelect: function (dateText, inst) {
//code to fill the other elements with the selected date goes here
$("#pickupCalendar").datepicker().hide();
$("#pickupCalendar img").hide();
}
});
});
相关文章:
- keith wood日期选择器日期格式和语言
- 如何将日期选择器日期转换为JSON对象以用于AJAX请求
- 如何使用下拉菜单修复jquery日期选择器日期计算功能
- jQuery:检索日期选择器日期,检查是否在日期范围内,显示/隐藏字段
- 存储日期选择器日期并保存在数据库中
- 基于Select值更改禁用jQueryUI日期选择器日期
- 从替代字段填充 jquery UI 日期选择器日期字段
- 如何获取引导时间选择器日期对象
- 角度材料的日期选择器日期错误
- Jquery日期选择器日期格式
- 启动日期选择器日期比较错误(英国/美国格式错误)
- 日期选择器日期空间问题
- 更改beforeShowDay函数中的日期选择器日期格式
- 如何使用jQuery比较两个日期选择器日期
- 日期选择器日期未定义
- 启动日期选择器日期范围和默认日期
- Bootstrap日期选择器日期(带或不带日期)
- 分析javascript中的日期选择器日期"dd月字符串,yyyy”;
- 通过输入字段中的天数更新日期选择器日期
- 显示2个日期选择器日期之间的天数