日期范围选择器 html5
date range picker html5
我想推出一个日期范围选择器,如下图所示。 ideal output
这是我现在执行的更新代码和我现在拥有的输出。
$(function() {
$("#fromperiod").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function(selectedDate) {
$("#toperiod").datepicker("option", "minDate", selectedDate);
}
});
$("#toperiod").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function(selectedDate) {
$("#fromperiod").datepicker("option", "maxDate", selectedDate);
}
});
});
.picker {
display: inline;
border: 1px solid lightgray;
padding : 4px;
}
input {
border: 0;
}
<link href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<table>
<tbody>
<tr>
<td>Period</td>
</tr>
<tr>
<td>
<div class='picker'>
<label for="fromperiod">From</label>
<input type="text" id="fromperiod" name="from">
<label for="toperiod">to</label>
<input type="text" id="toperiod" name="to">
</div>
</td>
</tr>
</tbody>
</table>
这是我基于代码的输出。 output
这里是一个关于如何设置样式的示例,它创建了一个包含阴影和边框的包装 #picker
元素,然后删除了子边框,并将它们置于内联。
.picker > * {
display:inline;
border:0;
}
.picker {
border:1px solid lightgray;
padding:4px;
box-shadow:inset 1px 1px 1px rgba(0,0,0,.1)
}
请看下面的例子,我修改了你的代码..
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
.wrapper{
display : inline;
border:1px solid lightgray;
padding:4px;
box-shadow:inset 1px 1px 1px rgba(0,0,0,.1)
}
input {
border:0;
}
label {
color : gray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css">
Period :
<div class='wrapper'>
<label for="from">from:</label>
<input type="text" id="from" name="from">
<label for="to">to:</label>
<input type="text" id="to" name="to">
</div>
我最近的任务是实现一个类似于 Google Analytics 中的日期范围选择器。经过一番搜索后,我发现 this JQueryUI widget that works very well, and can be styled easily using JQueryUI's ThemeRoller.
除非您正在学习或练习,否则使用现有代码、资产和库几乎总是最佳选择。正是出于这个原因,"Don't reinvent the wheel" 和 "Standing on the shoulders of giants" 这两个短语往往会在教室和演讲厅里随处可见!
我想推出一个日期范围选择器,如下图所示。 ideal output
这是我现在执行的更新代码和我现在拥有的输出。
$(function() {
$("#fromperiod").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function(selectedDate) {
$("#toperiod").datepicker("option", "minDate", selectedDate);
}
});
$("#toperiod").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function(selectedDate) {
$("#fromperiod").datepicker("option", "maxDate", selectedDate);
}
});
});
.picker {
display: inline;
border: 1px solid lightgray;
padding : 4px;
}
input {
border: 0;
}
<link href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<table>
<tbody>
<tr>
<td>Period</td>
</tr>
<tr>
<td>
<div class='picker'>
<label for="fromperiod">From</label>
<input type="text" id="fromperiod" name="from">
<label for="toperiod">to</label>
<input type="text" id="toperiod" name="to">
</div>
</td>
</tr>
</tbody>
</table>
这是我基于代码的输出。 output
这里是一个关于如何设置样式的示例,它创建了一个包含阴影和边框的包装 #picker
元素,然后删除了子边框,并将它们置于内联。
.picker > * {
display:inline;
border:0;
}
.picker {
border:1px solid lightgray;
padding:4px;
box-shadow:inset 1px 1px 1px rgba(0,0,0,.1)
}
请看下面的例子,我修改了你的代码..
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
.wrapper{
display : inline;
border:1px solid lightgray;
padding:4px;
box-shadow:inset 1px 1px 1px rgba(0,0,0,.1)
}
input {
border:0;
}
label {
color : gray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css">
Period :
<div class='wrapper'>
<label for="from">from:</label>
<input type="text" id="from" name="from">
<label for="to">to:</label>
<input type="text" id="to" name="to">
</div>
我最近的任务是实现一个类似于 Google Analytics 中的日期范围选择器。经过一番搜索后,我发现 this JQueryUI widget that works very well, and can be styled easily using JQueryUI's ThemeRoller.
除非您正在学习或练习,否则使用现有代码、资产和库几乎总是最佳选择。正是出于这个原因,"Don't reinvent the wheel" 和 "Standing on the shoulders of giants" 这两个短语往往会在教室和演讲厅里随处可见!