简体   繁体   English

创建单独的js文件以包含

[英]Create separate js file for inclusion

I have a html file in which currently resides all my javascript code. 我有一个html文件,当前所有我的javascript代码都位于其中。 I want to make a separate .js file, put all the javascript code in that and include that in my .html file. 我想制作一个单独的.js文件,将所有javascript代码放入其中,并将其包括在我的.html文件中。 I tried doing it, and also removed the opening/closing tags in the .js file and put this line in .html file - 我尝试这样做,还删除了.js文件中的开始/结束标签,并将此行放入.html文件中-

<script type='text/javascript' src="myfile.js"></script>

However, this is not working. 但是,这不起作用。 Any ideas on what's wrong? 有什么问题的想法吗? Thanks in advance. 提前致谢。

---------------------EDIT----------------------------- - - - - - - - - - - -编辑 - - - - - - - - - - - - - - --

<html>  

<title>Process Details</title>  

<head>  
<script type="text/javascript" src="https://www.google.com/jsapi"></script>  
<script type="text/javascript" src="myfile.js">  
</script>  

<style type="text/css">  
  body { font-size: 80%; font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; }  
  ul#tabs { list-style-type: none; margin: 30px 0 0 0; padding: 0 0 0.3em 0; }  
  ul#tabs li { display: inline; }  
  ul#tabs li a { color: #42454a; background-color: #dedbde; border: 1px solid #c9c3ba; border-bottom: none; padding: 0.3em; text-decoration: none; }  
  ul#tabs li a:hover { background-color: #f1f0ee; }  
  ul#tabs li a.selected { color: #000; background-color: #f1f0ee; font-weight: bold; padding: 0.7em 0.3em 0.38em 0.3em; }  
  div.tabContent { border: 1px solid #c9c3ba; padding: 0.5em; background-color: #f1f0ee; }  
  div.tabContent.hide { display: none; }  
  .heading { font-size:110%; font-family:'Century Schoolbook'; color: maroon; }  
  .data { font-size:110%; font-family:'Century Schoolbook'; color:black; }  
</style>  

</head>  

<body onload="init()">
<center>
<font face='Calibri' size='3' color='Blue'>PID : </font>
<select id='list' onchange="refreshData()">
</select>
<form>
<input type="button" id="Refresh" onclick="refreshPage()" value="Refresh Data"/>
</form>
</center>

<ul id="tabs">
<li><a href="#memory">Memory</a></li>
<li><a href="#thread">Thread</a></li>
<li><a href="#summary">Summary</a></li>
</ul>
<div class="tabContent" id="memory">
<table id="graphtab" align="center">

<tr>
<td id="heap" align="center"></td>
<td id="nonheap" align="center"></td>
</tr>
<tr>
<td id="resident" align="center"></td>
<td id="pagefaults" align="center"></td>
</tr>

</table>
</div>
<div class="tabContent" id="thread">
<table id="threadtab" align="center">

<tr>
<td id="cpuusage" align="center"></td>
<td id="count" align="center"></td>
</tr>
<tr>
<td id="threadlist" align="center"></td>
<td id="threaddets" align="center"></td>
</tr>

</table>
</div>
<div class="tabContent" id="summary">
</div>
<a href="client.html">Home Page</a>
</body>

</html>

Use http protocol instead of https . 使用http协议而不是https Using https throws a GET exception in Chrome but not Firefox . 使用https会在Chrome中引发GET异常, 但不会在 Firefox中引发。

And your <title> should be inside the <head> tag. 并且您的<title>应该在<head>标记内。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM