2011-02-16 46 views
0

我使用html,jquery和adobe air構建應用程序。在我的應用程序的一部分中,我使用jQuery提供的日期時間選擇器。如果我使用瀏覽器測試它們,它運行良好。但是,當我與Adobe AIR相結合,並使用AIR編譯它,它沒有工作....日期時間選擇器未在Adobe AIR中運行

這裏是我的代碼:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>jQuery UI Datepicker - Icon trigger</title> 
    <link rel="stylesheet" href="base/jquery.ui.all.css"> 
    <script type="text/javascript" src="js/jquery-1.4.4.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.core.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.widget.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.datepicker.js"></script> 
    <script type="text/javascript" src="js/AIRAliases.js"></script> 
    <link rel="stylesheet" href="css/demos.css"> 

    <script language="JavaScript"> 
     $(document).ready(function(){ 
      $("#datepicker").datepicker({ 
       showOn: "button", 
       buttonImage: "images/calendar.gif", 
       buttonImageOnly: true 
      }); 
     }); 
    </script> 
</head> 
<body> 

<div class="demo"> 

<p>Date: <input type="text" id="datepicker"></p> 

</div><!-- End demo --> 



<div class="demo-description"> 
<p>Click the icon next to the input field to show the datepicker. Set the datepicker to open on focus (default behavior), on icon click, or both.</p> 
</div><!-- End demo-description --> 

</body> 
</html> 

有誰能夠解決這個問題?謝謝

+0

你錯過了`在腳本上鍵入`-`屬性。其次,你有沒有嘗試隔離錯誤? `$()。ready()`是否工作,乾淨的日期選擇工作,其他插件的工作? – jerone 2011-02-16 07:41:50

回答

1

正如在這個post在jQuery UI開發小組中所述,它的當前形式的jQuery datepicker在Adobe Air中不起作用。 這報告在Bug #3945。 原因是Datepickers使用爲創建的Datepicker界面動態創建的onclick事件,Adobe Air內不允許執行此類操作以及eval()setTimeout()。 在作品中有一個修訂版本,有些人已經分支了主要代碼來嘗試修復,這些都記錄在上面的鏈接中。

0

正如AppSol所指出的那樣,這是jQuery UI和AIR的沙盒問題。但是,製作解決方案非常簡單。只需下載jQuery UI的未縮小版本,並在_updateDatepicker()函數的末尾添加以下內容。在上線16年1月8日的版本8954

$(".ui-datepicker-prev").click(function() { 
      $.datepicker._curInst.drawMonth--; 
      if ($.datepicker._curInst.drawMonth < 0) { 
       $.datepicker._curInst.drawMonth = 11; 
       $.datepicker._curInst.drawYear--; 
      } 
      $.datepicker._updateDatepicker($.datepicker._curInst); 
     }); 

     $(".ui-datepicker-next").click(function() { 
      $.datepicker._curInst.drawMonth++; 
      if ($.datepicker._curInst.drawMonth > 11) { 
       $.datepicker._curInst.drawMonth = 0; 
       $.datepicker._curInst.drawYear++; 
      } 
      $.datepicker._updateDatepicker($.datepicker._curInst); 
     }); 

     $(".ui-datepicker-calendar").find("tr > td").each(function() { 
      $(this).click(function() { 
       var t = $(this).attr('onclick').split('.')[2].split('(')[1].split(')')[0].split(','); 
       $.datepicker._selectDay(t[0].substr(1,t[0].length-2),t[1],t[2],this); 
      }); 
     }); 

下面是它應該如何看起來像在最後:

/* Generate the date picker content. */ 
_updateDatepicker: function(inst) { 
    var self = this; 
    self.maxRows = 4; //Reset the max number of rows being displayed (see #7043) 
    var borders = $.datepicker._getBorders(inst.dpDiv); 
    instActive = inst; // for delegate hover events 
    inst.dpDiv.empty().append(this._generateHTML(inst)); 
    var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only 
    if(!!cover.length){ //avoid call to outerXXXX() when not in IE6 
     cover.css({left: -borders[0], top: -borders[1], width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()}) 
    } 
    inst.dpDiv.find('.' + this._dayOverClass + ' a').mouseover(); 
    var numMonths = this._getNumberOfMonths(inst); 
    var cols = numMonths[1]; 
    var width = 17; 
    inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width(''); 
    if (cols > 1) 
     inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em'); 
    inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') + 
     'Class']('ui-datepicker-multi'); 
    inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') + 
     'Class']('ui-datepicker-rtl'); 
    if (inst == $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input && 
      // #6694 - don't focus the input if it's already focused 
      // this breaks the change event in IE 
      inst.input.is(':visible') && !inst.input.is(':disabled') && inst.input[0] != document.activeElement) 
     inst.input.focus(); 
    // deffered render of the years select (to avoid flashes on Firefox) 
    if(inst.yearshtml){ 
     var origyearshtml = inst.yearshtml; 
     setTimeout(function(){ 
      //assure that inst.yearshtml didn't change. 
      if(origyearshtml === inst.yearshtml && inst.yearshtml){ 
       inst.dpDiv.find('select.ui-datepicker-year:first').replaceWith(inst.yearshtml); 
      } 
      origyearshtml = inst.yearshtml = null; 
     }, 0); 
    } 
    $(".ui-datepicker-prev").click(function() { 
     $.datepicker._curInst.drawMonth--; 
     if ($.datepicker._curInst.drawMonth < 0) { 
      $.datepicker._curInst.drawMonth = 11; 
      $.datepicker._curInst.drawYear--; 
     } 
     $.datepicker._updateDatepicker($.datepicker._curInst); 
    }); 

    $(".ui-datepicker-next").click(function() { 
     $.datepicker._curInst.drawMonth++; 
     if ($.datepicker._curInst.drawMonth > 11) { 
      $.datepicker._curInst.drawMonth = 0; 
      $.datepicker._curInst.drawYear++; 
     } 
     $.datepicker._updateDatepicker($.datepicker._curInst); 
    }); 

    $(".ui-datepicker-calendar").find("tr > td").each(function() { 
     $(this).click(function() { 
      var t = $(this).attr('onclick').split('.')[2].split('(')[1].split(')')[0].split(','); 
      $.datepicker._selectDay(t[0].substr(1,t[0].length-2),t[1],t[2],this); 
     }); 
    }); 

}, 

這只是測試了jQuery UI的不過16年8月1日的想法在這個固定未來版本仍然保持不變。您需要將點擊事件處理程序添加到next和prev按鈕以及實際日期。