.js文件仅在html作为文件打开时才起作用,而在服务器上则不起作用 [英] .js files only work when html opened as file and not on servers

查看:102
本文介绍了.js文件仅在html作为文件打开时才起作用,而在服务器上则不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在线搜索了几个小时,没有解决办法.仅当在浏览器中而不是在localhost上将html作为文件打开html时,以下HTML中显示的.js文件才起作用.我已经尝试过"./subdirectory/file.js","/subdirectory/file.js"和"subdirectory/file.js".以文件形式打开时,所有表格都可以正常工作.

我已经在LAMP和AMPP上尝试了开发站点,结果相同.

目录结构

I have searched online for several hours with no solution. The .js files shown in the HTML below work only when the html is opened as a file in the browser and not on localhost. I have tried "./subdirectory/file.js", "/subdirectory/file.js", and "subdirectory/file.js". All forms work fine when opened as a file.

I have tried my developement site on both LAMP and AMPPs with the same results.

Directory structure

wwwroot
    index.html
    js/
    css/





<link rel="stylesheet" href="./css/style.css" type="text/css" media="all"/>
		<link rel="stylesheet" href="./css/jquery-ui-1.8.16.custom.css" type="text/css" media="all" />
		<script src="./js/libs/modernizr-2.0.min.js"></script>
		<script src="./js/libs/respond.min.js"></script>
		<!-- Script for external links in new window -->
		<script type="text/javascript" src="./js/external.js"></script>
		<!-- Scripts for tab panel -->
		<script type="text/javascript" src="./js/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="./js/jquery-ui-1.8.16.custom.min.js"></script>

推荐答案

最后!!!可以正常使用http://docs.jquery.com/Using_jQuery_with_Other_Libraries.必须与样板模板发生冲突.我在表和其他html页上的选项卡上都有jquery脚本.我不得不使用jquery.noconflect().

样本:
Finally!!! Got it to work curtsy of http://docs.jquery.com/Using_jQuery_with_Other_Libraries. Must have been having a conflict with Boilerplate template. I had jquery scripts for both the table and, on the other html page, the tabs. I had to use jquery.noconflect().

sample:
<script type="text/javascript">
		 // Use jQuery via


j(...)使用jQuery var
j(...) var


j = jQuery.noConflict();
j = jQuery.noConflict();


这篇关于.js文件仅在html作为文件打开时才起作用,而在服务器上则不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆