JavaScript SRC 路径不起作用

发布于 2024-08-16 23:02:57 字数 1122 浏览 10 评论 0 原文

我在网上搜索过答案,但似乎这次我没有那么幸运,所以我被迫问。如果已经回答(找不到),我深表歉意。是的,英语不是我的母语,所以我也为我的拼写错误道歉,我尽力了。

这是我的问题,使用 Tomcat 5.5、Struts 1.3、JRE 1.5,我使用的是 firefox 3.5.6。 在我的 jsp 页面中,我似乎无法在

这是我的代码:

<script type="text/javascript" src="js/jquery-1.3.2.js">
    function showMySelf(){
        alert("Hello World!");      
    }
(... plus other stuff code that actually uses jquery functions)
</script>

和提交按钮:

<input type="submit" onclick="showMySelf()">

当我单击按钮时,没有任何反应(实际上它重新绘制了页面),当我从脚本中删除“src”标签并将所有 jquery 代码添加到页面时,一切正常出色地。

我尝试在路径中添加另一个斜杠作为“/js/jquery-1.3.2.js”并返回错误。

我尝试过使用 ResolveURL,但它似乎没有给我更好的结果。

我还尝试将 js 文件更改为另一个文件(“generics.js”和“js.js”),我还尝试了“js/*.js”。

这些解决方案中的任何一个都已存档任何内容。

我也尝试过使用 struts 标签(如 html:submit),但它也不起作用。

该路径实际上是正确的,因为在我的网络浏览器中查看代码会给我一个 js 文件的链接。所以我假设浏览器知道要查找我的 js 文件,它不会给我错误或文件链接损坏。

对于为什么会发生这种情况有什么想法吗?

谢谢大家。

随机的。

I have searched this web looking for an answer, but it seems that this time I'm not so lucky, so I am forced to ask. I apologize if it's already answered (could not find it). And yes, English is not my first language, so I also apologize for my spelling mistakes, I try my best.

This is my problem, using Tomcat 5.5, Struts 1.3, JRE 1.5 and I'm using firefox 3.5.6.
In my jsp page I cannot seem to put any src="path/path" in my <script> I have tried deleting the src and all works well, but my project is going to need a lot of use from jquery and I do not want to copy/paste all the js file in every jsp.

This is my code:

<script type="text/javascript" src="js/jquery-1.3.2.js">
    function showMySelf(){
        alert("Hello World!");      
    }
(... plus other stuff code that actually uses jquery functions)
</script>

and the submit button:

<input type="submit" onclick="showMySelf()">

When I click the button, nothing happens (well it actually repaints the page) and when I delete the "src" tag from the script and add all the jquery code to the page it all works well.

I have tried putting another slash in the path as "/js/jquery-1.3.2.js" and returns an error.

I have tried using ResolveURL and it doesn't seem to give me better results.

I have also tried changing the js file to another file ("generics.js" and "js.js"), I also tried with "js/*.js".

Any of theese solutions have archived anything.

I have also tried using the struts tags (like html:submit) but it also did not work.

The path is actually right, since looking the code in my web browser gives me a link to the js file. So I suposse the browser knows were to look for my js file, it does not give me an error or a broken link to the file.

Any ideas of why this is happening?

Thank you all.

Random.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

坐在坟头思考人生 2024-08-23 23:02:57

您不能使用 script 元素加载外部文件并同时将代码放入其中。您需要使用两个 script 元素:

<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
    function showMySelf(){
        alert("Hello World!");      
    }
(... plus other stuff code that actually uses jquery functions)
</script>

You can not use a script element to load an external file and put code in it at the same time. You need to use two script elements:

<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
    function showMySelf(){
        alert("Hello World!");      
    }
(... plus other stuff code that actually uses jquery functions)
</script>
凑诗 2024-08-23 23:02:57

我认为冈博解决了这个问题。

作为旁注,确定浏览器是否可以加载 JS 文件的一个非常好的方法是 Firebug。它显示当前页面的所有已加载(和失败)请求。

I think Gumbo solved it.

As a sidenote, a very good way to find out whether a browser can load a JS file is the "Net tab" in Firebug in Firefox. It shows all loaded (and failed) requests of the current page.

断爱 2024-08-23 23:02:57

两个最可能的选项是:

a) 您在 JS 文件中包含 HTML(即

将其取出。

b) 您的 URI 错误,当您尝试手动解析相对 URI 时,您的操作不正确

查看服务器访问日志以查看实际请求的内容(或使用 Firebug 等工具)

The two most likely options are:

a) You are including HTML in your JS file (i.e. <script> tags)

Take it out.

b) You have the wrong URI and when you attempt to resolve your relative URI manually you do so incorrectly

Look at your server access logs to see what is actually being requested (or use a tool such as Firebug)

ゝ偶尔ゞ 2024-08-23 23:02:57

在这种情况下首先要做的就是。安装 Firebug 并查看“Console”面板(可能存在语法错误)和“Net”面板以查看是否正确获取 jQuery 源。第二列显示请求状态代码。
替代文本 http://img46.imageshack.us/img46/6224/jqueryfirebugtmp.jpg< /a>
(全尺寸图片)

The first thing to do in such case. Install Firebug and look at the "Console" panel (for possible syntax errors) and the "Net" panel to see whether your jQuery sources are being fetched correctly. The 2nd column there shows the request status code.
alt text http://img46.imageshack.us/img46/6224/jqueryfirebugtmp.jpg
(full size image)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文