2014-09-27 147 views
2
<!doctype html> 
<html lang="en"> 
<head> 

<meta charset="utf-8"> 
<meta content='width=device-width, initial-scale=1' name='viewport'/> 
    <title>jQuery UI Datepicker</title> 

    <link type="text/css" href="jquery-ui-1.8.16.custom/css/sunny/jquery-ui-1.8.16.custom.css" rel="stylesheet" /> 
    <script src="jquery-ui-1.8.16.custom/js/jquery-1.6.2.min.js"></script> 

    <script scrc="jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script> 
</head> 
<body> 
    <h3>Date of Birth</h3> 
    <input type="text" name="birth_date" id="datepicker"> 
    <script> 
     $(document).ready(function(){ 
      $('#datepicker').datepicker(); 
     }); 
    </script> 
</body> 
</html> 

爲什麼這不起作用?嘗試了幾次,但在調試中得到相同的錯誤:Datepicker不起作用

對象不支持屬性或方法'datepicker'。

+0

看來你沒有包含datepicker.js和jquery-ui庫。 – 2014-09-27 12:24:31

+0

我認爲jquery.js和jquery-ui中存在版本控制問題。只要包含他們的最新版本。 – 2014-09-27 12:28:45

+0

你使用jQuery 1.6嗎?如果是,那麼我不確定它是否支持日期選擇器。更新jQuery插件至少1.7.2,它將工作http://jsfiddle.net/dimomohit/2js1cykh/。希望這可以幫助你。 – DimoMohit 2014-09-27 12:31:58

回答

1

看起來你有一個錯字這裏

<script scrc="jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script> 
---------^ 

任何錯誤scrc應更改爲src

<script src="jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script> 
+0

謝謝。這確實是一個錯字。現在工作正常。 – ranjan 2014-09-27 12:54:37

0

試試這個小提琴Demo - here,在你的代碼檢查包括腳本正確加載,或者檢查控制檯顯示

<link type="text/css" href="jquery-ui-1.8.16.custom/css/sunny/jquery-ui-1.8.16.custom.css" rel="stylesheet" /> 
    <script src="jquery-ui-1.8.16.custom/js/jquery-1.6.2.min.js"></script> 

    <script src="jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script> 
</head>