2

好的,我在 htdocs 中有一个 js 文件,当我将它包含在我的 php 页面中时它不起作用但是当我从网上加载它时它起作用了,我不知道它有什么问题。我有:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> test</title>
</head>

我将 js 文件放在页面底部,这不起作用,

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="js/boostrap.js"></script>
<script type="text/javascript" src="js/wpts_slider_multiple.js"></script>

这行得通,

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.jqueryslidershock.com/wp-content/plugins/tsslider/js/boostrap.js"></script>
<script type="text/javascript" src="http://www.jqueryslidershock.com/wp-content/plugins/tsslider/js/wpts_slider_multiple.js"></script>
4

4 回答 4

1

try this: src="/js/boostrap.js"> instead of src="js/boostrap.js">

the / is your root path

you can use this absolute path /js/boostrap.js in php, js, css files, and it works fine.

<script type="text/javascript" src="/js/boostrap.js"></script>
<script type="text/javascript" src="/js/wpts_slider_multiple.js"></script>
于 2013-10-09T05:22:12.133 回答
0

try giving the paths like

<script type="text/javascript" src="/js/boostrap.js"></script>
<script type="text/javascript" src="/js/wpts_slider_multiple.js"></script>

src='/js/boostrap.js'

Assuming your root is http://localhost then the above link should always resolve to http://localhost/ProjectName/js/boostrap.js whether it's called from http://localhost/ProjectName/index.php or http://localhost/ProjectName/subdir/index.php

Make sure the js files are present within your folder structures

Always try to give relative paths to your files so that they can be easily found.

于 2013-10-09T05:22:24.453 回答
0

你应该给full path你的jquery files喜欢

http://example.com/js/boostrap.js

代码

<script src="http://example.com/js/boostrap.js"></script>
<script src="http://example.com/js/wpts_slider_multiple.js"></script>
于 2013-10-09T05:24:48.487 回答
0

以下任一情况正在发生。

路径不正确- 请检查文件路径。

JS 文件没有读取权限- 如果您确定本地 JS 文件的路径正确,请检查其read权限。

文件不存在- 原因很简单。我相信事实并非如此。

让我知道你发现了什么。

于 2013-10-09T05:25:42.150 回答