2014-02-25 25 views
-1
var dates = [new Date(2014, 02 - 1, 19), 
      new Date(2014, 02 - 1, 20), 
      new Date(2014, 02 - 1, 21), 
      new Date(2014, 01 - 1, 21) 
      ]; 

與我的數據輸入,但我有我的數據從數據庫,自動寫入。 我不太瞭解jQuery,我是初學者。jQuery with Ajax,mysql,從邏輯數據提取

我想要做什麼:數據庫作爲變量的數據定義

HTML代碼:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="iso-8859-9"> 
    <title>jQuery UI Datepicker - Türkçe Takvim Textbox'u...</title> 
    <link rel="stylesheet" href="css/jquery.ui.all.css"> 
    <link rel="stylesheet" href="css/demos.css"> 
    <script src="js/jquery-1.7.1.js"></script> 
    <script src="js/jquery.ui.core.js"></script> 
    <script src="js/jquery.ui.widget.js"></script> 
    <script src="js/jquery.ui.datepicker.js"></script> 
    <script src="js/jquery.ui.datepicker-tr.js"></script> 
    <style type="text/css"> 
#highlight, .highlight { 
    /*background-color: #000000;*/ 
} 
.highlight > a.ui-state-default { 
    background: url("images/ui-bg_highlight-soft_25_ffef8f_1x100.png") repeat-x scroll 50% top #FFEF8F !important; 
    border: 1px solid #F9DD34; 
    color: #363636; 
} 
    </style> 

<script type="text/javascript"> 
var dates = [new Date(2014, 02 - 1, 19), 
      new Date(2014, 02 - 1, 20), 
      new Date(2014, 02 - 1, 21), 
      new Date(2014, 01 - 1, 21) 
      ]; 

$(function() { 

    $('#datepicker').datepicker({ 
     numberOfMonths: [1, 1], 
     beforeShowDay: highlightDays 
    }).click(function() { 
     $('.ui-datepicker-today a', $(this).next()).removeClass('ui-state-highlight ui-state-hover'); 
     //$('.highlight a', $(this).next()).addClass('ui-state-highlight'); 
    }); 


    $('#datepicker').click(function() { 
     // put your selected date into the data object 
     var data = $('#datepicker').val(); 
/* 
     $.get('getdata.php?date=' + data, function(data) { 
      $('#events').html(data).show('slow'); 
     });*/ 
    }); 

    function highlightDays(date) { 
     for (var i = 0; i < dates.length; i++) { 
      if (dates[i].getTime() == date.getTime()) { 
       return [true, 'highlight']; 
      } 
     } 
     return [true, '']; 
    } 
}); 
    </script> 
</head> 
<body> 
<div id="datepicker"></div> 
</body> 
</html> 
+0

你能更準確的瞭解您的問題 – dreamweiver

回答

0

如果我理解正確,你要使用從數據您的數據庫作爲JavaScript中的變量,然後您可以操作。

如果你聲明你的日期,也申明一個變量var dbData;。然後在您的聽衆:

$('#datepicker').click(function() { // put your selected date into the data object var selectedDate = $('#datepicker').val(); $.get('getdata.php?date=' + selectedDate, function(data) { //assign the values returned from the php call to a variable dbData = data; //$('#events').html(data).show('slow'); }); });

的主要問題(假設你的PHP文件是做什麼它應該)是你的聽衆,你兩次定義的數據變量。通過將其更改爲使用不同的變量名稱,可以更新JavaScript變量以包含您的get請求返回的數據。

如果您正在尋找操作,你會數據庫表中的get函數返回在JavaScript中幾乎相同的方式將數據更先進的方式,看看http://www.taffydb.com/