那里有人为jQuery mobile提供了一个很好的约会选择器吗?
我将让用户选择“从”日期和“到”日期,我没有找到任何有利于这种情况。
有什么想法吗?
答案 0 :(得分:29)
我建议使用Datebox
https://github.com/jtsage/jquery-mobile-datebox
或Mobiscroll
如果您想要Android风味的东西,请尝试我自己的Mobi Pick
答案 1 :(得分:19)
尝试Mobiscroll,一个针对触摸设备优化的可自定义日期选择器
答案 2 :(得分:6)
这是专门针对移动设备的日期选择器
http://jquerymobile.com/demos/1.0a4.1/experiments/ui-datepicker/
答案 3 :(得分:5)
我致力于将jquery ui datepicker更新为最新版本的jquery,jqueryui和jquery mobile,以便jq1.9.1 jqui 1.10.2和jqm 1.3.0。我喜欢像以前的回答一样离开,所以你可以看到它是如何演变的。
changeMonth和changeYear下拉列表需要特别注意工作(不经常使用)
这是我如何更新jqmobile的实验性jqueryui datepicker:
您可以链接到datepicker脚本而不是整个jqueryui包。
readonly prop阻止键盘出现在ios上
这只是对日期选择器进行调整以使其在jqm上运行,目标是能够覆盖datepicker小部件的_generatehtml函数,并能够作为输入使用jquery移动主题。所以你不需要那一堆addClass并避免不必要的DOM操作
我只测试了ios 6(iphone,ipad)和桌面(chrome,firefox,safari),让我们了解其他测试。
希望它能够根据需要提供帮助:)
这里是以html,js和css分隔的所有代码:
<强> HTML 强>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jqueryui 1.10.2 datepicker Integration in jquery mobile 1.3.0 and jquery 1.9.1 by aureltime</title>
<link rel="stylesheet" href="//ajax.aspnetcdn.com/ajax/jquery.mobile/1.3.0/jquery.mobile-1.3.0.min.css">
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>jQuery UI's Datepicker Styled for mobile adapted by Aureltime</h1>
</div>
<div data-role="content">
<form action="#" method="get" id="form">
<div data-role="fieldcontain">
<label for="date">Date:</label>
<input type="date" name="date" id="date" value="" />
</div>
</form>
</div>
</div>
</body>
</html>
<强> JS 强>
//reset type=date inputs to text
$.mobile.page.prototype.options.degradeInputs.date = true;
$("#form").trigger("create");
$( document )
.on( "pageinit", function(){
$("#date")
.prop("readonly", "true")
.on("click", function(){
$input=$(this);
$next=$input.next();
if($next.hasClass("hasDatepicker"))
$next.hide();
$input
.hide()
.after( $( "<div />", { id : "datepicker_"+$input.attr("id")}).datepicker(
{
altField : "#" + $input.attr( "id" ),
altFormat : "dd/mm/yy",
defaultDate : $input.val(),
showOtherMonths : true,
selectOtherMonths : true,
//showWeek : true,
changeYear : true,
changeMonth : true,
//showButtonPanel : true,
//beforeShowDay : beforeShowDay,
onSelect : function( dateText, inst)
{ $("#datepicker_"+$input.attr("id")).hide();
$input.show();
}
}));
});
});
(function($, undefined ) {
//cache previous datepicker ui method
var prevDp = $.fn.datepicker;
//rewrite datepicker
$.fn.datepicker = function( options ){
var dp = this;
//call cached datepicker plugin
prevDp.call( this, options );
//extend with some dom manipulation to update the markup for jQM
//call immediately
function updateDatepicker(event){
$( ".ui-datepicker-header", dp ).addClass("ui-body-c ui-corner-top").removeClass("ui-corner-all");
$( ".ui-datepicker-prev, .ui-datepicker-next", dp ).attr("href", "#");
$( ".ui-datepicker-prev", dp ).buttonMarkup({iconpos: "notext", icon: "arrow-l", shadow: true, corners: true});
$( ".ui-datepicker-next", dp ).buttonMarkup({iconpos: "notext", icon: "arrow-r", shadow: true, corners: true});
$( ".ui-datepicker-calendar th", dp ).addClass("ui-bar-c");
$( ".ui-datepicker-calendar td", dp ).addClass("ui-body-c");
$( ".ui-datepicker-calendar a", dp ).buttonMarkup({corners: false, shadow: false});
$( ".ui-datepicker-calendar a.ui-state-active", dp ).addClass("ui-btn-active"); // selected date
$( ".ui-datepicker-calendar a.ui-state-highlight", dp ).addClass("ui-btn-up-e"); // today"s date
if(typeof event != "undefined")
{
var classe= $(event.target).attr("class");
//alert(classe);
}
$( ".ui-datepicker-calendar .ui-btn", dp ).each(function(){
var el = $(this);
var buttonText = el.find( ".ui-btn-text" );
// remove extra button markup - necessary for date value to be interpreted correctly
if(buttonText.length)
el.html( el.find( ".ui-btn-text" ).text() );
});
// }
$( dp )
.off()
.on( "click", updateDatepicker)
.find("select")
.on( "change", function(event){updateDatepicker(event);});
}
//update now
updateDatepicker();
//return jqm obj
return this;
};
})( jQuery );
CSS
div.hasDatepicker{ display: block; padding: 0; overflow: visible; margin: 8px 0; }
.ui-datepicker { overflow: visible; margin: 0; max-width: 500px; }
.ui-datepicker .ui-datepicker-header { position:relative; padding:.4em 0; border-bottom: 0; font-weight: bold; }
.ui-datepicker .ui-datepicker-prev, .ui-datepicker .ui-datepicker-next { padding: 1px 0 1px 2px; position:absolute; top: .5em; margin-top: 0; text-indent: -9999px; }
.ui-datepicker .ui-datepicker-prev { left:6px; }
.ui-datepicker .ui-datepicker-next { right:6px; }
.ui-datepicker .ui-datepicker-title { margin: 0 2.3em; line-height: 1.8em; text-align: center; }
.ui-datepicker .ui-datepicker-title select { font-size:1em; margin:1px 0; }
.ui-datepicker select.ui-datepicker-month-year {width: 100%;}
.ui-datepicker select.ui-datepicker-month,
.ui-datepicker select.ui-datepicker-year { width: 49%;}
.ui-datepicker table {width: 100%; border-collapse: collapse; margin:0; }
.ui-datepicker td { border-width: 1px; padding: 0; text-align: center; }
.ui-datepicker td span, .ui-datepicker td a { display: block; padding: .2em 0; font-weight: bold; margin: 0; border-width: 0; text-align: center; text-decoration: none; }
.ui-datepicker-calendar th { padding-top: .3em; padding-bottom: .3em; }
.ui-datepicker-calendar th span, .ui-datepicker-calendar span.ui-state-default { opacity: .3; }
.ui-datepicker-calendar td a { padding-top: .5em; padding-bottom: .5em; }
以下是与jqm 1.4配合使用的更新版本:jsbin jqm 1.4.0
考虑到jquery mobile 1.4.0的变化,需要少量的dom操作
答案 4 :(得分:3)
这里是我对这里另一篇文章的回答的副本,关于如何在jquerymobile framwework中集成jqueryui datepicker ...它有帮助,就像它会帮助我,如果它存在:)
在互联网上进行了大量搜索之后,特别是比较了datebox和jqueryui datepicker(mobiscroll和mobipick对我来说并不好,因为我正在寻找日历视图,我到了我决定使用ui datepicker的地步理由:我用它:
使用更新版本的datepicker会打破月/年更改的布局。
来自here,我得到了我需要的文件。我在不同的stackoverflow问题上使用了几个答案,进行了以下更改:
jquery.ui.datepicker.mobile.js新代码:
(function ($, undefined) {
//cache previous datepicker ui method
var prevDp = $.fn.datepicker;
//rewrite datepicker
$.fn.datepicker = function (options) {
var dp = this;
//call cached datepicker plugin
var retValue = prevDp.apply(this, arguments);
//extend with some dom manipulation to update the markup for jQM
//call immediately
function updateDatepicker() {
$(".ui-datepicker-header", dp).addClass("ui-body-c ui-corner-top").removeClass("ui-corner-all");
$(".ui-datepicker-prev, .ui-datepicker-next", dp).attr("href", "#");
$(".ui-datepicker-prev", dp).buttonMarkup({ iconpos: "notext", icon: "arrow-l", shadow: true, corners: true });
$(".ui-datepicker-next", dp).buttonMarkup({ iconpos: "notext", icon: "arrow-r", shadow: true, corners: true });
$(".ui-datepicker-calendar th", dp).addClass("ui-bar-c");
$(".ui-datepicker-calendar td", dp).addClass("ui-body-c");
$(".ui-datepicker-calendar a", dp).buttonMarkup({ corners: false, shadow: false });
$(".ui-datepicker-calendar a.ui-state-active", dp).addClass("ui-btn-active"); // selected date
$(".ui-datepicker-calendar a.ui-state-highlight", dp).addClass("ui-btn-up-e"); // today"s date
$(".ui-datepicker-calendar .ui-btn", dp).each(function () {
var el = $(this);
// remove extra button markup - necessary for date value to be interpreted correctly
// only do this if needed, sometimes clicks are received that don't require update
// e.g. clicking in the datepicker region but not on a button.
// e.g. clicking on a disabled date (from next month)
var uiBtnText = el.find(".ui-btn-text");
if (uiBtnText.length)
el.html(uiBtnText.text());
});
};
//update after each operation
updateDatepicker();
$( dp ).on( "click change", function( event, ui)
{
$target=$(event.target);
if(event.type=="click" && ($target.hasClass("ui-datepicker-month") || $target.hasClass("ui-datepicker-year")))
event.preventDefault();
else
updateDatepicker( event);
});
//return jqm obj
if (retValue) {
if (!retValue.jquery) return retValue;
}
return this;
};
})(jQuery);
我使用on()而不是click事件,我在单击月/年选择菜单时阻止默认。
我用这种方式:
$form
.trigger( "create" )
.find( "input[type='date'], input:jqmData(type='date')")
.each(function()
{
$(this)
.after( $( "<div />" ).datepicker(
{
altField : "#" + $(this).attr( "id" ),
altFormat : "dd/mm/yy",
showOtherMonths : true,
selectOtherMonths : true,
showWeek : true,
changeYear : true,
changeMonth : true,
beforeShowDay : beforeShowDay
}));
});
with beforeShowDay是一个返回数组的函数(参见jqueryui datepicker手册)。
这对我有用,我现在只需要在日期输入得到关注时添加事件,只显示日历。
答案 5 :(得分:1)
试用Mobiscroll插件。它是一个很棒的插件。我对它的体验非常好。我有一个关于设置&#34; 开始日期&#34;的实例。和&#34; 结束日期&#34;。您可以在 jsFiddle
上查看此示例Here is source code for start and end date example
HTML:
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="http://example.gajotres.net/iscrollview/mobiscroll-2.4.custom.min.css" />
<link rel="stylesheet" href="http://www.fajrunt.org/mobiscroll.custom-2.5.1.min.css"/>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="http://example.gajotres.net/iscrollview/mobiscroll-2.4.custom.min.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-role="content">
<input name="demo" id="demo" class="i-txt" />
</div>
<div data-role="content">
<input name="demo2" id="demo2" class="i-txt" />
</div>
</div>
</body>
</html>
Javascript & Jquery:
$(document).on('pagebeforeshow', '#index', function(){
$('#demo').mobiscroll().date({
//invalid: { daysOfWeek: [0, 6]},
theme: 'android-ics',
display: 'inline',
mode: 'scroller',
dateOrder: 'mm dd yy',
dateFormat : "mm-dd-yy",
minDate: new Date(2015,03,16),
maxDate: new Date(2015,11,03),
});
$('#demo2').mobiscroll().date({
// invalid: { daysOfWeek: [0, 6]},
theme: 'android-ics',
display: 'inline',
mode: 'scroller',
dateOrder: 'mm dd yy',
dateFormat : "mm-dd-yy",
minDate: new Date(2015,3,21),
maxDate: new Date(2015,11,3)
});
$("#demo").change(function(){
getNextdate();
});
$("#demo2").change(function(){
getPdate();
});
});
function getNextdate() {
var tt = document.getElementById('demo').value;
var date = new Date(tt);
var newdate = new Date(date);
newdate.setDate(newdate.getDate()+5);
var dd = newdate.getDate();
if(dd<10) {dd='0'+dd}
var mm = newdate.getMonth()+1;
if(mm<10) {mm='0'+mm}
var y = newdate.getFullYear();
var someFormattedDate = mm + '-' + dd + '-' + y;
document.getElementById('demo2').value = someFormattedDate;
}
function getPdate() {
var tt = document.getElementById('demo2').value;
var date = new Date(tt);
var newdate = new Date(date);
newdate.setDate(newdate.getDate()-5);
var dd = newdate.getDate();
if(dd<10) {dd='0'+dd}
var mm = newdate.getMonth()+1;
if(mm<10) {mm='0'+mm}
var y = newdate.getFullYear();
var someFormattedDate = mm + '-' + dd + '-' + y;
document.getElementById('demo').value = someFormattedDate;
}
感谢Gajotres提供初步帮助
答案 6 :(得分:0)
此时您可能知道,jquery mobile 1.4.5有一个(带插件): http://demos.jquerymobile.com/1.4.5/datepicker/
答案 7 :(得分:0)
Here is the full code from Juery document:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Format date</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
$( "#format" ).change(function() {
$( "#datepicker" ).datepicker( "option", "dateFormat", 'yy-mm-dd' ); // I am using the internationl date format, you can choose yours following below six options.
});
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" size="30"></p>
<p>Format options:<br>
</body>
</html>`
Notices: DateFormat have 5 options :
1.mm/dd/yy
2.yy-mm-dd
3.d M, y
4.d MM, y
5.DD, d MM, yy
6.'day' d 'of' MM 'in the year' yy