jquery datepicker显示在测试字段下。有一段时间它会在文本字段的顶部。但我希望将datepicker始终显示在测试字段的顶部。怎么做?将jquery datepicker的位置设置为文本字段顶部
回答
You can try this :
$('#txtDate').datepicker({
beforeShow: function (textbox, instance) {
instance.dpDiv.css({
marginTop: (-textbox.offsetHeight) + 'px',
marginLeft: textbox.offsetWidth + 'px'
});
}
});
使用您自己的风险...
.ui-datepicker {
position: relative !important;
top: -290px !important;
left: 0 !important;
}
您可能需要更新顶级像素,因为它取决于你的基本字体大小。
$('#StartDateIssued,#EndDateIssued,#StartDateFulFill,#EndDateFulFill').datepicker({
beforeShow: function (input, inst) {
var offset = $(input).offset();
var height = $(input).height();
window.setTimeout(function() {
inst.dpDiv.css({ top: (offset.top + height - 20) + 'px', marginLeft: (input.offsetWidth) + 'px' })
})},
changeMonth: true, changeYear: true, constrainInput: true,
dateFormat: "dd-mm-yy", onSelect: function (dateText, inst) {
$('#StartDateIssued').valid();
$('#StartDateIssued').val(dateText);
}
});
jQuery的日期选择器的设计就像它不需要任何修改......只可以向左或向右移动通过在该日期选择器的CSS的变化,检查你的HTML版本,因为没有按日期选择器” T公司的支持HTML 5版.. HTML版本4支持
我们可以用Jquery Ui做很多配置。 – Jyothu 2016-09-12 13:22:35
$('#txtDate').datepicker({
beforeShow: function (textbox, instance) {
instance.dpDiv.css({
marginTop: (-textbox.offsetHeight) + 'px',
marginLeft: textbox.offsetWidth + 'px'
});
}
});
如果你在一个页面中两个或两个以上datepickers,这个代码改变所有的人的位置。如果您需要单独改变每一个,你应该使用这个代码...
beforeShow: function (input, inst) {
setTimeout(function() {
inst.dpDiv.css({
top: 100,
left: 200
});
}, 0);
}
我试图用这个这个技巧,在原有基础上的jQuery UI的“_checkOffset”功能解决方法:
function datepickerInitDirectionReverse() {
// Store original method to be able to call it inside our overriding method.
$.datepicker._checkOffset_original = $.datepicker._checkOffset;
$.datepicker._checkOffset = function(inst, offset, isFixed) {
var dpHeight = inst.dpDiv.outerHeight(),
inputHeight = inst.input ? inst.input.outerHeight() : 0,
viewTop = isFixed ? 0 : $(document).scrollTop();
offset = $.datepicker._checkOffset_original(inst, offset, isFixed);
// Try to reposition the datepicker on top of it,
// only if the option flag is set by the user
// and only if this has not already happened.
offset.top -= Math.min(
offset.top,
(
this._get(inst, "directionReverse")
&&
(offset.top > inst.input.offset().top)
&&
(offset.top - viewTop > dpHeight)
) ? Math.abs(dpHeight + inputHeight) : 0
);
return offset;
}
}
现在,你可以在每个元素的基础上进行如下配置定位偏好:
// Prefer datepicker to appear on top of input element (if room).
$(element).datepicker({
directionReverse: true
});
// Prefer datepicker to appear on bottom of input element (if room).
// This is the unchanged default behaviour.
$(element).datepicker({
directionReverse: false
});
要注意的是上述可能在jQuery用户界面的未来版本打破,如果开发商决定改变接口。请让我知道是否会有任何副作用。
以下代码会将日历始终放在输入字段的顶部。
$('.txtDate').datepicker({
beforeShow: function (textbox, instance) {
var txtBoxOffset = $(this).offset();
var top = txtBoxOffset.top;
var left = txtBoxOffset.left;
var textBoxWidth = $(this).outerWidth();
console.log('top: ' + top + 'left: ' + left);
setTimeout(function() {
instance.dpDiv.css({
top: top-190, //you can adjust this value accordingly
left: left + textBoxWidth//show at the end of textBox
});
}, 0);
}});
要让日历显示在文本框的左上角,请按照[小提琴](http://jsfiddle.net/ezkc4p12/) – 2016-10-18 02:42:11
- 1. jquery datepicker在文本字段上方的位置
- 2. 将焦点设置为文本字段
- 3. 将javafx中的DatePicker字段设置为空字段?
- 4. 将导航位置设置为滚动顶部
- 5. Struts2 JQuery DatePicker:将maxDate设置为今天
- 6. 如何在位置顶部设置TextField?
- 7. 将日期文本字段设置为数字日期字段
- 8. 将文本设置为文本字段的问题
- 9. 使用增加高度将文本视图设置为顶部
- 10. 设置文本字段中的Carret位置(Win32API)
- 11. 如何将DIV放置在JQuery的顶部和绝对位置?
- 12. AS3设置文本字段
- 13. jQuery datepicker输入字段设置为“不可点击”
- 14. 在GridLayout中将TextView设置为顶部
- 15. 在tkinter文本部件中设置插入字符的位置
- 16. 将键盘设置为仅英文语言的文本字段
- 17. 如何在Android中将AlertDialog的位置设置为顶部的屏幕?
- 18. Jquery-ui Draggable不会将初始位置的顶部位置更改为初始位置的负数
- 19. jQuery为文本字段的输入值设置动画效果
- 20. 文本字段()设置插入符位置
- 21. Eclipse Scout在字段中设置文本位置
- 22. 如何设置datepicker的显示位置?
- 23. jQuery中的DatePicker设置一个值,但将相关的文本框为空
- 24. Jquery:将动画导航栏设置为滑动条顶部
- 25. 如何设置Angular UI Bootstrap Datepicker默认设置空字段?
- 26. 将viewbag值和文本设置为相同的字段
- 27. 位置标记在位置顶部的位置?
- 28. 如何在字段中设置占位符文本的样式?
- 29. MATLAB:将当前文件夹设置为脚本的位置
- 30. 将插入位置设置为多个文本框的末端
http://www.mindfiresolutions.com/Make-jQuery-datepicker-to-popup-in-different-positions-995.php。它会显示在文本框的右侧:http://jsfiddle.net/4mGkn/ – Eli 2013-03-27 11:56:00