1

私はJQueryMobileの実験Datepickerをしばらく使用していましたが、古いフレームワークで動作しました。昨日、フレームワークを最新のものに変更したところ、外側をクリックすると Datepicker のレイアウトが崩れることがわかりました。

壊れたレイアウト

誰かが同じ問題に遭遇しましたか?? どうやって乗り越えましたか?? これは、datepicker が最新のフレームワークでサポートされないことを意味しますか??

私のコードは以下のようになります

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Page Title</title> 

    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <link rel="stylesheet" href="jquery.mobile-1.1.0.min.css" />
    <link rel="stylesheet"  href="jquery.ui.datepicker.mobile.css" /> 
    <script src="jquery-1.7.2.min.js"></script>



    <script>
  //reset type=date inputs to text
  $( document ).bind( "mobileinit", function(){
    $.mobile.page.prototype.options.degradeInputs.date = true;

  });

  $(function() {
        $( "#datepicker" ).datepicker();
    });

  </script>
  <script src="jquery.mobile-1.1.0.min.js"></script>
    <script src="jQuery.ui.datepicker.js"></script>
    <script src="jquery.ui.datepicker.mobile.js"></script>
</script>
</head> 
<body> 

<div data-role="page">

    <div data-role="header">
        <h1>Page Title</h1>
    </div><!-- /header -->

    <div data-role="content">   
        <label for="date">Date Input:</label>
        <input type="date" name="date" id="date" value=""  /> 

        <div id='datepicker'></div>
    </div><!-- /content -->

    <div data-role="footer">
        <h4>Page Footer</h4>
    </div><!-- /footer -->
</div><!-- /page -->

</body>
</html>
4

6 に答える 6

3

同じ問題が発生し、日付ピッカー API を変更しました。これを使用すると、iOS、Android、jQuery Mobile、モード、モーダルなどの UI を jQuery コードと一緒に設定するなど、必要なものがすべて提供されます。

jQuery モバイル日付ピッカー

これを使用した後、問題が発生することはありません。

于 2012-05-03T04:56:39.260 に答える
2

このコードはjquery.ui.datepicker.mobile.js の updateDatepicker(); のすぐ下にあります。

$( ".ui-datepicker-calendar .ui-btn", dp ).each(function(){
var el = $(this);
// remove extra button markup - necessary for date value to be interpreted correctly
el.html( el.find(".ui-btn-text").text() );   
});

交換

el.html( el.find(".ui-btn-text").text() ); 

el.text( el.text() ); 

それは私のために働いた:)

于 2012-06-29T17:19:10.120 に答える
1

これを使用することもできます:

Jquery モバイル日付ピッカー

これが 1.1 で動作するかどうかは確認していませんが、最新の状態に保たれており、多くの機能が提供されています。

于 2012-05-03T20:07:23.937 に答える
1

インターネットで多くの検索を行った後、特に datebox と jqueryui datepicker を比較しました (カレンダー ビューを探しているので、mobiscroll と mobipick は私には適していません)。いくつかの理由で ui datepicker を使用することにしました。

  • 私は長い間それを使用しています、私はそれを十分に知っています
  • クラスで日をカスタマイズするには、beforeShowDay(日付ボックスとイベント/コールバックを使用して同様の機能を持つことが確かに可能である場合のイベント)が必要でした
  • 月と年を変更できるヘッダーが必要でした(日付ボックスでも可能です)
  • この実験で、私はすでにjquerymobileの感じと見た目を備えたdatepickerを持っていました

私はそれを使用しました:

最近のバージョンで datepicker を使用すると、月/年の変更時にレイアウトが壊れます。

ここから、必要なファイルを取得しました。次の変更を加えるために、さまざまなスタックオーバーフローの質問で見つけたいくつかの回答を使用しました。

  • jquery.ui.datepicker.mobile.css に変更はありません
  • 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() を使用し、月/年の選択メニューのクリックを防ぎます。

そして、私はそれをこのように使用します:

$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
                }));
        });

beforeShowDay は配列を返す関数です (jqueryui datepicker マニュアルを参照)。

このように機能し、日付入力がフォーカスされたときにのみカレンダーを表示するようにイベントを追加する必要があります。

jsbin の例へのリンク

于 2013-01-07T09:24:36.093 に答える
0

Android と iPhone のフリップ (2 回のフリップで日付と時刻の両方) に有効なカスタム日時ピッカーを作成しました。

https://github.com/ngethe/jQM-DateBoxNgethe

于 2013-11-19T23:21:41.883 に答える
0

他の場所の回答のコピー:

jquery ui datepicker を jquery 、 jqueryui 、および jquery mobile の最新バージョンに更新する作業を行ったので、jq1.9.1、jqui 1.10.2 および jqm 1.3.0 に対応しました。以前の回答のままにしたかったので、それがどのように進化したかがわかります。

changeMonth と changeYear ドロップダウンが機能するために特別な注意が必要でした (unstylying が頻繁に行われました)

ここでは、jqmobile の実験的な jqueryui datepicker を更新する方法を示します。

js ビン コード スニペット

jqueryui パッケージ全体ではなく、datepicker スクリプトにリンクできます。

readonly prop により、キーボードが ios に表示されなくなります

日付ピッカーをjqmで動作させるのは単なる微調整です。目標は、日付ピッカーウィジェットの_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; }
于 2013-03-22T10:29:14.720 に答える