I have two input fields for which I'm using datepicker:
我有两个输入字段,我正在使用datepicker:
- On the first I want to hide the day selector and the 'Today' button.
- On the second I want a normal datepicker
在第一个我想要隐藏日期选择器和“今天”按钮。
在第二个我想要一个普通的datepicker
To achieve the desired effect on the 1st, I'm using a hack, like:
为了达到预期的效果,我正在使用黑客,如:
$('.date-picker').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
With CSS:
.ui-datepicker-calendar {
display: none;
}
HTML:
<label for="startDate">Date :</label>
<input name="startDate" id="startDate" class="date-picker" />
<label for="startDate">Outra Data :</label>
<input name="outraData" id="outraData" />
I tried:
#startDate .ui-datepicker-calendar {
display: none;
}
And:
.date-picker .ui-datepicker-calendar {
display: none;
}
Here's a JSFiddle
这是一个JSFiddle
2 个解决方案
#1
1
You can simply apply the css [By inspecting using dev tools(F12)]
你可以简单地应用css [通过使用开发工具检查(F12)]
.ui-datepicker-current{
display: none ;
}
#2
0
Remove the following option in your datepicker to hide the buttons:
删除日期选择器中的以下选项以隐藏按钮:
showButtonPanel: true
Since you want 2 different datepickers, use the following:
由于您需要2个不同的日期选择器,请使用以下内容:
HTML
<label for="startDate">Date :</label>
<input name="startDate" id="startDate" />
<label for="startDate">Outra Data :</label>
<input name="outraData" id="outraData" />
JS
$('#startDate').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'MM yy',
onClose: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
$('#outraData').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
Notice that i have called the datepickers on the basis of IDs.
请注意,我已根据ID调用了datepickers。
#1
1
You can simply apply the css [By inspecting using dev tools(F12)]
你可以简单地应用css [通过使用开发工具检查(F12)]
.ui-datepicker-current{
display: none ;
}
#2
0
Remove the following option in your datepicker to hide the buttons:
删除日期选择器中的以下选项以隐藏按钮:
showButtonPanel: true
Since you want 2 different datepickers, use the following:
由于您需要2个不同的日期选择器,请使用以下内容:
HTML
<label for="startDate">Date :</label>
<input name="startDate" id="startDate" />
<label for="startDate">Outra Data :</label>
<input name="outraData" id="outraData" />
JS
$('#startDate').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'MM yy',
onClose: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
$('#outraData').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
Notice that i have called the datepickers on the basis of IDs.
请注意,我已根据ID调用了datepickers。