我试图使用jQuery的日期选择器: http://jqueryui.com/datepicker/jQuery中的Datepicker UI src不起作用,但Google的src不起作用。为什么?
有趣的是,我复制源代码粘贴到一个.html文件,并在Chrome中打开它。日期选择器不起作用。这里是来源:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
但是,我将脚本和CSS的来源从jQuery更改为谷歌,它突然起作用。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
我很高兴看到它的工作,但我不明白为什么。这是特别令人困惑的,因为我想直接来自jQuery的src,这个代码的来源应该比Google提供的更可靠,对吗?
你必须使用网络服务器,像WAMP或EasyPHP,否则''//不会作为协议工作。 – adeneo 2015-03-18 23:24:39
我刚刚复制了你的完全代码,它在铬中工作。您正在使用哪个浏览器? – user86745458 2015-03-18 23:27:21
刚添加http:在//之前,它的作品!随意添加,作为答案,我可以关闭这个问题。谢谢! – 2015-03-18 23:27:38