简体   繁体   English

尝试将本地Javascript文件链接到HTML文档,但是在浏览器中,我收到“无法加载资源”错误

[英]Trying to link a local Javascript file to HTML document but in the browser, I receive a Failed to load resource error

I'm trying to link a javascript file to my html document. 我正在尝试将javascript文件链接到我的html文档。

I'm following the instructions on http://dubrox.github.io/Multiple-Dates-Picker-for-jQuery-UI/#demo-days-range to select multiple dates from a calendar as input in a form. 我正在按照http://dubrox.github.io/Multiple-Dates-Picker-for-jQuery-UI/#demo-days-range上的说明从日历中选择多个日期作为表单中的输入。

It says "You include both jQuery and jQuery UI (with datepicker module included!) javascript files to your HTML page, and right after that, include MultiDatesPicker". 它说:“您在HTML页面中同时包含了jQuery和jQuery UI(包括datepicker模块!)JavaScript文件,并在其后添加了MultiDatesPicker”。

<script src="https://code.jquery.com/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="jquery-ui.multidatespicker.js"</script>

Which I have done. 我已经做了。

Note jquery-ui.multidatespicker.js is in my local project directory as it's own file not in any folders. 注意jquery-ui.multidatespicker.js在我的本地项目目录中,因为它是自己的文件,不在任何文件夹中。 You can download a zip file on the github page where this file is included. 您可以在包含此文件的github页面上下载一个zip文件。

Then I call the multidatespicker function in the head of the document. 然后,我在文档的开头调用multidatespicker函数。

<script type="text/javascript">
        $(function() {

        $('#mdp-demo').multiDatesPicker();

 });
    </script>

And finally within the body you write your html input id to be used in the function 最后,在正文中编写要在函数中使用的html输入id

 <input id="mdp-demo">

When I run this in the browser I get an error "Failed to load resource: the server responded with a status of 404 (NOT FOUND)" for jquery-ui.multidatespicker.js:1. 在浏览器中运行此脚本时,对于jquery-ui.multidatespicker.js:1,出现错误“无法加载资源:服务器响应状态为404(未找到)”。

If you scroll down to the demos on the multiple dates github page and go to "Form input". 如果您向下滚动到多个日期github页面上的演示,然后转到“表单输入”。 That is what i'm trying to achieve. 那就是我想要达到的目标。 The problem is that my jquery-ui.multidatespicker.js script search isn't finding the script and therefore doesn't recognize the .multiDatesPicker() function. 问题是我的jquery-ui.multidatespicker.js脚本搜索找不到该脚本,因此无法识别.multiDatesPicker()函数。

Any suggestions as to what I'm doing wrong? 关于我在做什么错的任何建议吗?

You should use CDN link for multidatespicker 您应该将CDN链接用于multidatespicker

<script src="https://cdn.jsdelivr.net/npm/jquery-ui-multidatespicker@1.6.6/jquery-ui.multidatespicker.js"></script>

If you want to use <script src="jquery-ui.multidatespicker.js"</script> you need download file an put at same HTML folder and it will work. 如果您想使用<script src="jquery-ui.multidatespicker.js"</script> ,则需要在同一个HTML文件夹中放置一个put文件,该文件才能正常工作。 Also note that you missing > for open tag. 另请注意,您缺少>的开放标签。

 $(function() { $('#mdp-demo').multiDatesPicker(); }); 
 <script src="https://code.jquery.com/jquery.min.js"></script> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script src="https://cdn.jsdelivr.net/npm/jquery-ui-multidatespicker@1.6.6/jquery-ui.multidatespicker.js"></script> <input id="mdp-demo" /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么浏览器会尝试从服务器加载本地 JavaScript 文件? - Why is the browser trying to load a local JavaScript file from a server? 为什么当我尝试将 javascript 文件链接到 html 时浏览器显示找不到文件错误? - why is the browser shows me file not found error when i try to link javascript file to html? 无法加载资源,Javascript,HTML5 - Failed to load resource, Javascript, HTML5 html / javascript链接到本地​​文件 - html/javascript link to a local file 编织到 HTML 文档并在服务器上运行时出现“不允许加载本地资源”错误 - "Not allowed to load local resource" error when knitting to HTML document and running on a server 错误不允许在 javaScript 中加载本地资源 - Error Not allowed to load local resource in javaScript 无法为JavaScript中的Ajax调用加载资源错误 - Failed to load resource error for ajax call in javascript 尝试将 MediaSource 对象附加为 HTML5 视频标签的源时出现“不允许加载本地资源”错误 - Getting "Not allowed to load local resource" error while trying to attach a MediaSource object as the source of a HTML5 video tag 尝试在 HTML 页面加载时读取本地文件 - Trying to read a local file on page load in HTML 在本地html文件上评估javascript(无需浏览器) - Evaluate javascript on a local html file (without browser)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM