1
在我的處境:幫助!月份更改後如何在UI日期選擇器中啓用日期?
我得到了希望從被調用的ajax啓用的日子。當我改變這個月的時候,我讀了XML文件小瓶阿賈克斯調用,並得到了那個月的日子。如何讓它出來?
非常感謝你!
數組變量來保存天數:
var $daysWithRecords = new Array()
函數加載XML文件:
function getDays(year,month){
$.ajax({
type: "GET",
url: "users.xml",
dataType: "xml",
success:function(msg)
{
initDaysArray($(msg) , year , month);
}
});
}
功能草簽天陣:
function initDaysArray($xml , year , month)
{
//alert(year+'-'+month);
var dateToFind = year+'-'+month;
var $myElement = $xml.find('user[id="126"]');
dates = '';
$myElement.find('whDateList[month="'+dateToFind+'"]').find('date').each(function(){
$daysWithRecords.push(dateToFind+$(this).text());
dates += $(this).text() + ' ';
});
console.log(dates);
console.log($daysWithRecords.length)
}
功能,使這一天可用的數組變量:
function checkAvailability(avalableDays){
var $return=false;
var $returnclass ="unavailable";
$checkdate = $.datepicker.formatDate('yy-mm-dd', avalableDays);
for(var i = 0; i < $daysWithRecords.length; i++){
if($daysWithRecords[i] == $checkdate){
$return = true;
$returnclass= "available";
}
}
return [$return,$returnclass];
}
日期選擇器部分的代碼加載和顯示天[注:我使用的日期選擇器的在線模式]
$('#div').datepicker({ dateFormat: 'yy-mm-dd',defaultDate: '2010-09-01' ,
onChangeMonthYear: function(year, month, inst) {
console.log(year);
console.log(month);
getDays(year,month);
} ,
beforeShowDay: checkAvailability
});
,並最終我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<users>
<user id="126">
<name>john</name>
<watchHistory>
<whMonthRecords month="2010-10">
<whDateList month="2010-10">
<date>01</date>
<date>05</date>
<date>21</date>
</whDateList>
</whMonthRecords>
<whMonthRecords month="2010-11">
<whDateList month="2010-11">
<date>01</date>
<date>05</date>
<date>06</date>
<date>07</date>
<date>08</date>
<date>09</date>
<date>12</date>
<date>13</date>
<date>14</date>
<date>16</date>
<date>18</date>
<date>19</date>
<date>21</date>
<date>22</date>
<date>23</date>
<date>24</date>
<date>25</date>
<date>26</date>
<date>29</date>
</whDateList>
</whMonthRecords>
</watchHistory>
</user>
</users>
非常感謝你許多!!
真棒!!非常感謝! – qinHaiXiang 2010-11-13 11:16:47
@秦海翔 - 歡迎光臨!檢查你的其他問題,我注意到它是相關的:) – 2010-11-13 11:26:46
是的,我正在運行一個我自己的項目。謝謝你的幫助!! – qinHaiXiang 2010-11-13 14:11:36