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. jquery datepicker在文本字段上方的位置
- 3. 如何將光標位置設置爲文本字段的初始位置?
- 4. 將焦點設置爲文本字段
- 5. 將javafx中的DatePicker字段設置爲空字段?
- 6. jquery slideToggle css頂部位置
- 7. 將導航位置設置爲滾動頂部
- 8. 如何將setZOrderOnTop設置爲true的GLSurfaceView頂部的片段設置爲
- 9. Struts2 JQuery DatePicker:將maxDate設置爲今天
- 10. 設置jQuery偏移()頂部
- 11. jQuery UI的位置右上方設置的CSS到左頂部
- 12. 如何使用jQuery將值設置爲數組文本字段
- 13. 如何在位置頂部設置TextField?
- 14. 將日期文本字段設置爲數字日期字段
- 15. 將文本字段設置爲隱藏字段值 - 未設置值
- 16. 將文本設置爲文本字段的問題
- 17. 使用增加高度將文本視圖設置爲頂部
- 18. 設置文本字段中的Carret位置(Win32API)
- 19. 將文本置於UIlabel的頂部
- 20. AS3設置文本字段
- 21. 設置字段文本,Java
- 22. 如何將DIV放置在JQuery的頂部和絕對位置?
- 23. NullPointerException設置文本字段的文本
- 24. jQuery datepicker輸入字段設置爲「不可點擊」
- 25. 在GridLayout中將TextView設置爲頂部
- 26. jquery datepicker max設置
- 27. jQuery頂部錯誤的位置()
- 28. jQuery Masonry錯誤的頂部位置
- 29. 在tkinter文本部件中設置插入字符的位置
- 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