jQuery 日期选择器 - 代码不起作用?
jQuery datepicker - code won't work?
jQuery 的新手。我无法让日期选择器工作。谁能告诉我我做错了什么?谢谢,任何帮助表示赞赏。这是框架代码:
<html>
<head>
<title>Example</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>
<script>
$(function() {
$("#quoteDate").datepicker();
});
</script>
</head>
<body>
<input type="text" id="quoteDate">
</body>
</html>
我看过许多与此几乎相同的帖子,但 none 的答案有效。我还下载了 jQuery UI 文件以在本地引用它们,但这也不起作用。
他们不在本地为您工作,因为您是 运行 他们来自 url 文件,例如 file:///Macintosh HD/whatever...
.
您需要更改行:
<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="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
当您为资产使用 //
前缀时,它会匹配您使用的任何协议。因此,当您在本地加载某些内容时(不使用本地 Web 服务器),它会查找不存在的 file:///code.jquery.com/jquery-1.10.2.js
。将资产更改为以 http://
或 https://
开头,而不是 //
.
阅读以上答案和您的评论后,您似乎无法在浏览器本地 运行 它。
在本地引用文件
最简单的方法是下载所有文件并将其保存在同一目录中。
假设文件是
index.htm
、jquery-ui.css
、jquery-1.10.2.js
、jquery-ui.js
文件:index.htm
<html>
<head>
<title>Example</title>
<link rel="stylesheet" href="jquery-ui.css">
<script src="jquery-1.10.2.js"></script>
<script src="jquery-ui.js"></script>
<script>
$(function() {
$("#quoteDate").datepicker();
});
</script>
</head>
<body>
<input type="text" id="quoteDate">
</body>
</html>
相对路径
可以给出相对路径如
src="js/jquery-1.10.2.js"
src="js/jquery-ui.js"
href="css/jquery-ui.css"
如果目录结构是:
Present Working Directory
index.htm
js (directory)
jquery-1.10.2.js
jquery-ui.js
css (directory)
jquery-ui.css
jQuery 的新手。我无法让日期选择器工作。谁能告诉我我做错了什么?谢谢,任何帮助表示赞赏。这是框架代码:
<html>
<head>
<title>Example</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>
<script>
$(function() {
$("#quoteDate").datepicker();
});
</script>
</head>
<body>
<input type="text" id="quoteDate">
</body>
</html>
我看过许多与此几乎相同的帖子,但 none 的答案有效。我还下载了 jQuery UI 文件以在本地引用它们,但这也不起作用。
他们不在本地为您工作,因为您是 运行 他们来自 url 文件,例如 file:///Macintosh HD/whatever...
.
您需要更改行:
<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="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
当您为资产使用 //
前缀时,它会匹配您使用的任何协议。因此,当您在本地加载某些内容时(不使用本地 Web 服务器),它会查找不存在的 file:///code.jquery.com/jquery-1.10.2.js
。将资产更改为以 http://
或 https://
开头,而不是 //
.
阅读以上答案和您的评论后,您似乎无法在浏览器本地 运行 它。
在本地引用文件
最简单的方法是下载所有文件并将其保存在同一目录中。
假设文件是
index.htm
、jquery-ui.css
、jquery-1.10.2.js
、jquery-ui.js
文件:index.htm
<html>
<head>
<title>Example</title>
<link rel="stylesheet" href="jquery-ui.css">
<script src="jquery-1.10.2.js"></script>
<script src="jquery-ui.js"></script>
<script>
$(function() {
$("#quoteDate").datepicker();
});
</script>
</head>
<body>
<input type="text" id="quoteDate">
</body>
</html>
相对路径
可以给出相对路径如
src="js/jquery-1.10.2.js"
src="js/jquery-ui.js"
href="css/jquery-ui.css"
如果目录结构是:
Present Working Directory
index.htm
js (directory)
jquery-1.10.2.js
jquery-ui.js
css (directory)
jquery-ui.css