javascript - jquery datepicker - 将日期选择器放在文本字段下

标签 javascript jquery html datepicker

我有一个考试日期字段,如下图所示:

enter image description here

我的代码:

<html>
<head>
<link rel="stylesheet" href="js/jquery-ui-themes-1.11.1/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.11.1/jquery-ui.js">    </script>
<script type="text/javascript">
$(function(){
    $("#datepicker1").datepicker({dateFormat: 'dd-mm-yy'});
});
</script>
<style>
.ui-datepicker{
    font-size: 9.5pt;
}

.ui-widget-header{
    font-size: 12px;
    color: #102132;
    background: #D7E5F2;
}

#ui-datepicker-div .ui-state-highlight{
    background: yellow;
    color: red;
    font-weight: bold;
}

.ui-datepicker-current-day .ui-state-active{
    background: white;
    color: blue;
    font-weight: bold;
}
</style>
</head>

<body>
<input type="text" name="examdate" id="datepicker1" /> 
</body>
</html>

现在我的问题是,当我单击文本字段时,我想要文本字段下方的日期选择器。应该如何修改?

最佳答案

$(function(){
   	$("#datepicker1").datepicker({
	dateFormat: 'mm/dd/yy',
	beforeShow: function (input, inst) {
		var rect = input.getBoundingClientRect();
		setTimeout(function () {
			inst.dpDiv.css({ top: rect.top + 40, left: rect.left + 0 });
		}, 0);
	}
});

});
<style>
.ui-datepicker{
    font-size: 9.5pt;
}

.ui-widget-header{
    font-size: 12px;
    color: #102132;
    background: #D7E5F2;
}

#ui-datepicker-div .ui-state-highlight{
    background: yellow;
    color: red;
    font-weight: bold;
}

.ui-datepicker-current-day .ui-state-active{
    background: white;
    color: blue;
    font-weight: bold;
}
</style>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.js"></script>

<input type="text" name="examdate" id="datepicker1" />

关于javascript - jquery datepicker - 将日期选择器放在文本字段下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34282206/

相关文章:

javascript - 使用 Azure 中的 Angular 应用程序和 Rest 服务进行 CORS 验证

javascript - 在悬停系列名称 Highcharts 上添加消息

javascript - 在 Asp.Net Core 3 Web 应用程序中仅显示一次模式

javascript - 将一个 HTML 文档呈现到另一个 HTML 文档中

javascript - 导航栏动画

html - 如何防止 Div 重叠

javascript - d3.js 不读取 JSON (d3.js + dc.js + crossfilter)

javascript - 更改每个网址的一部分

javascript - 为什么这个 JavaScript 原型(prototype)函数会破坏 jQuery?

javascript - 如何在背景图像中启用视频或照片?