【发布时间】:2019-01-24 20:24:16
【问题描述】:
我指的是this 文章并尝试创建一个没有范围的月份滑块。我想从此滑块中删除范围,因为我只需要一个月和一年。请在下面找到我更新的代码。
function formatDate(date) {
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var monthIndex = date.getMonth();
var year = date.getFullYear();
return monthNames[monthIndex] + ' ' + year;
}
$(document).ready(function() {
$("#range-slider").slider({
range: "min",
min: new Date('2012-01-01T00:00:00').getTime(),
max: new Date('2019-01-01T00:00:00').getTime(),
step: 86400000,
value:new Date('2015-03-01T00:00:00').getTime() ,
slide: function(event, ui) {
$( "#amount" ).val( formatDate(new Date(ui.values[1])));
}
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p>
<label for="amount">date range:</label>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;width:400px;">
</p>
<div id="range-slider"></div>
如果我替换它会很好用
value:new Date('2015-03-01T00:00:00').getTime() ,
到
values: [ new Date('2015-03-01T00:00:00').getTime(),new Date('2015-03-01T00:00:00').getTime() ],
请告诉我这段代码有什么问题。
【问题讨论】:
-
你只需要“12months' name”还是“month name + Year”?
-
@saAction 我需要两个“月名+年”
标签: jquery jquery-ui jquery-ui-slider