[英]JQuery: toggle date-picker in when clicked on a span tag
Here, I am trying to add a birthdate but with this code: 在这里,我尝试添加生日,但是使用以下代码:
<script>
$('#datepicker').focus(function() {
$("#datepicker").datepicker();
});
</script>
I am not able to toggle the jquery datepicker off! 我无法关闭jquery datepicker! this is my html: 这是我的HTML:
<div class="DOB">
<span class="DOB" contenteditable="true" id="datepicker">25/09/1996</span>
<hr />
<span class="st">Date of birth</span>
</div>
I don't want JQuery datepicker on my screen all the time! 我不想一直在屏幕上显示Jquery datepicker!
please help... 请帮忙...
You can do something like this 你可以做这样的事情
var show = 1;
$('#datepicker').focus(function() {
if(show == 1)
{
$( "#datepicker" ).datepicker("show");
show = 0;
}
else
{
$( "#datepicker" ).datepicker("hide");
show = 1;
}
});
I searched for this on other sites and this works fine except that I cannot switch between months or if I shut it down without choosing a date it leaves the space blank!... 我在其他网站上搜索了此文件,但除我无法在数月之间切换,或者如果我不选择日期就将其关闭而将其留空的情况下,它就可以正常工作!
<script>
$(function() {
$('#datepicker').click(function() {
$(this).datepicker({
onSelect: function(date) {
$(this).datepicker('destroy').html(date);
}
});
});
$('body').click(function(e) {
if ($(e.target).closest('#datepicker').length == 0) {
$('#datepicker').datepicker('destroy');
}
});
});
</script>
This will work definitely, and if possible please find the solution for switching months and blank space problem! 这绝对可以工作,如果可能,请找到解决月份和空白问题的解决方案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.