2015-01-27 71 views
-1

我使用從jQuery UI的文檔這個非常簡單的日期選擇器的代碼,但它並不在我的Mac工作:jQuery的日期選擇器不響應

<!doctype html> 
<html> 
<head> 
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 
    <script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
</head> 

<body> 
    <input type="text" id="date-picker" /> 
    <script> 
     $("#date-picker").datepicker(); 
    </script> 
</body> 

誰能告訴我,爲什麼它不起作用?提前致謝!

+0

你之前包括jQuery的,你也有兩個引用jQuery的JS,檢查:HTTP:// jsfiddle.net/bwjb02rf/ – 2015-01-27 00:14:26

回答

2

jQuery UI依賴於jQuery。

因此你需要的jQuery UI的腳本之前包括jQuery腳本:

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 
<script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 

無需包括jQuery的兩次無論是。以上就足夠了。

這裏是一個working example

+0

但是,不是與jQuery UI有關的第一行嗎? – Drexel 2015-01-27 00:20:02

+0

第一行是樣式表。在這種情況下,它的順序不會影響它下面的腳本('.js'文件)。 – 2015-01-27 00:21:21

+1

第一行是jQuery UI的css,你可以在任何地方加載它。 – 2015-01-27 00:22:13

1

你應該在添加jqueryui之前添加jquery。
您加入jQuery的twice.Remove一個

<!doctype html> 
    <html> 
    <head> 
     <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
    </head> 
     <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 
    <!-- <script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script>--> 


    <body> 
    <input type="text" id="date-picker" /> 
    <script> 
     $("#date-picker").datepicker(); 
    </script> 
    </body> 
+0

非常感謝您的回答! – Drexel 2015-01-27 00:25:05

1

yeahh包括jQuery的jQuery UI的前

<!doctype html> 
<html> 
<head> 
    <script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 
</head> 

<body> 
    <input type="text" id="date-picker" /> 
    <script> 
     $("#date-picker").datepicker(); 
    </script> 
</body>