javascript 错误:找不到 jquery.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14216961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:02:01  来源:igfitidea点击:

error: jquery.js is not found

javascriptruby-on-rails

提问by Alon Shmiel

I wrote the next row in index.html.erb:

我写了下一行index.html.erb

<script src="/app/assets/javascripts/jquery.js"></script>

I added the file: jquery.jsto the folder: app/assets/javascripts

我将文件:添加到文件jquery.js夹中:app/assets/javascripts

but in the console, I got an error:

但在控制台中,我收到一个错误:

GET http://localhost:3000/app/assets/javascripts/jquery.js 404 (Not Found)

please help.

请帮忙。

采纳答案by kuldeep raj

Please use this one

请用这个

 <script src="assets/jquery.js" type="text/javascript"></script>

this one is good for you

这个对你有好处

回答by lante

The problem is from where are you calling the jquery.jsfile. I mean, it depends of where do you have your index.htmlfile.

问题是你从哪里调用jquery.js文件。我的意思是,这取决于您的index.html文件在哪里。

For example, if your index.html is on /app/index.html, try:

例如,如果您的 index.html 是 on /app/index.html,请尝试:

<script src="assets/javascripts/jquery.js"></script>

回答by bullfrog

Can you not use the rails helpers on this ?

你不能在这个上使用 rails helpers 吗?

<%= javascript_include_tag "jquery" %>

回答by Chris Salzberg

You don't need the full path, just assets/jquery.jsis enough:

您不需要完整路径,就assets/jquery.js足够了:

<script src="assets/jquery.js"></script>

回答by R Milushev

I think that the most common place to define javascript files to add is the manifest file: app/assets/javasripts/application.js. It looks like this :

我认为定义要添加的 javascript 文件的最常见位置是manifest file: app/assets/javasripts/application.js。它看起来像这样:

//= require jquery
//= require jquery-ui
//= require jquery_ujs

Then you have your assets added application-wide .

然后,您将资产添加到应用程序范围内。