[英]HTML - Linking an external Javascript file
I can't figure out why my external Javascript file isn't being linked to by my HTML file. 我不知道为什么我的HTML文件没有链接我的外部Javascript文件。 I have
我有
<script type="text/javascript" src="jobs.js"></script>
in my HTML header and 在我的HTML标头中
window.onload = function () { alert("Working");
}; };
in my Javascript file. 在我的Javascript文件中。
I'm using the firefox extension Firebug and it's telling me that my webpage isn't loading my Javascript file. 我正在使用firefox扩展名Firebug,它告诉我我的网页未加载我的Javascript文件。 What am I doing wrong?
我究竟做错了什么? Thanks
谢谢
edit: I've checked the path many times, I've moved the .js file to the same folder now. 编辑:我已经检查了很多次,现在我已经将.js文件移到了相同的文件夹。
<!DOCTYPE html>
< html lang="en"> <html lang =“ zh_CN”>
<meta charset="utf-8" />
<meta name="description" content="Home Page" />
<meta name="author" content="Caitlin Reeve" />
<link rel="Stylesheet" type="text/css" href="styles/style.css" />
<script type="text/javascript" src="jobs.js"></script>
<Title> Home Page</Title>
<!-- Image Source: http://cdn.business2community.com/wp-content/uploads/2013/03/Hat3.png-->
<a name="logo" href= "index.html"><img src="images/Hat3.png" alt="Business Logo" /></a>
<h1>Tech Solutions </h1>
<hr />
<!-- Site Menu -->
<nav>
<p></p>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="job1.html" >Jobs</a></li>
<li><a href="enquire.html" >Enquire</a></li>
<li><a href="about.html">About</a></li>
</ul>
</nav>
<h3> Application </h3>
<form action="http://mercury.ict.swin.edu.au/it000000/formtest.php" name="applyJob" method="POST" >
<fieldset>
<legend> Your Details </legend>
Job Reference Number <input required="required" name="jobno" type="text" required="required" /><br />
First Name <input required="required" name="fname" type="text" pattern="[A-Za-z]{1,15}" maxlength="15" required="required" /><br />
Last Name <input required="required" name="lname" type="text" pattern="[A-Za-z]{1,25}" maxlength="25" required="required"/><br />
Date of Birth <input required="required" name="dob" type="date" pattern="[(0[1-9]|[12][0-9]|3[01])[/]((0[1-9]|1[012])[/](19|20)\d\d][(0[1-9]|[12][0-9]|3[01])[/]((0[1-9]|1[012])[/][(0[0-9]|1[0-9]\d\d)]" required="required"/><br />
Gender
<label><input type="radio" value="Male" name="gender" checked="checked" /> Male </label>
<label><input type="radio" name="gender" value="Female" /> Female </label> <br />
<p>
Address: <br />
Street Address <input required="required" name="streetad" type="text" maxlength="50" required="required" /><br />
Suburb/Town <input required="required" name="subad" type="text" maxlength="25" required="required" /><br />
State <select required="required" name="state">
<option value="">Choose</option>
<option value="WA">WA</option>
<option value="NT">NT</option>
<option value="SA">SA</option>
<option value="QLD">QLD</option>
<option value="NSW">NSW</option>
<option value="VIC" selected="selected" >VIC</option>
<option value="ACT">ACT</option>
<option value="TAS">TAS</option>
</select>
</p>
<br />
Postcode <input required="required" name="postcode" type="text" pattern="[0-9]{4}" required="required"/><br />
<br />
Email Address <input required="required" name="email" type="email" required="required" /><br />
Phone Number <input required="required" name="phone" type="tel" pattern="[0-9]{10}" maxlength="10" required="required"/><br />
<p>
Skills <br />
<label><input required="required" type="checkbox" name="HTML" value="html" required="required" /> HTML experience</label><br />
<label><input required="required" type="checkbox" name="Degree" value="degree" required="required" /> Degree (Bachelor or higher) </label> <br />
<label><input required="required" type="checkbox" name="SQL" value="sql" required="required" /> SQL experience </label> <br />
<label><input type="checkbox" name="lift" value="lift" /> Able to lift heavy objects </label> <br />
<label><input type="checkbox" name="experience" value="years" /> 3 or more years of experience </label> <br />
<label><input type="checkbox" name="RubyPython" value="languages" /> Ruby or Python knowledge </label> <br />
<label><input type="checkbox" name="other" value="other" /> Other Skills </label>
</p>
Other Skills <br />
<textarea rows="3" COLS="25"></textarea><br />
fps 帧/秒
<!--Submits the form to the server-->
<input type="submit" value="Submit Application" />
</fieldset>
</form>
2014 2014年
Provided that your path is good and that the js file does load, there is one thing to fix: the onload listener needs to be a function: 假设您的路径正确并且js文件确实已加载,则需要修复的一件事:onload侦听器必须是一个函数:
window.onload = function(){
alert("Working");
}
Your js
file must be placed in the same folder as your html
. 您的
js
文件必须与html
放在同一文件夹中。
html/
|__myHtml.html
|__jobs.js
If it is in other folder, eg: 如果在其他文件夹中,例如:
html/
|__myHtml.html
js/
|__jobs.js
then change the relative path to your javascript: 然后将相对路径更改为您的javascript:
<script type="text/javascript" src="../js/jobs.js"></script>
looks like you missing the function () call. 好像您错过了function()调用。 see revised code below tested it in firefox quickly and it worked.
看到下面的修订代码在firefox中对其进行了快速测试,并且可以正常工作。 your external link looks fine.
您的外部链接看起来不错。
window.onload = function () { alert("Working");
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.