1
我正在嘗試爲簡歷頁面製作工資計算器。我的功能工作時,其內部然而,當我將其更改爲外部我的按鈕和功能不起作用。我'嘗試在中心div做到這一點。忽略了其他頁面部分,因爲這些只是鏈接。
任何幫助非常感謝!外部JS文件按鈕調用
這裏是我的HTML:
<!DOCTYPE html>
<html>
<!--External-->
<head>
<title>Resume of Michael R. Young </title>
<link rel = "stylesheet" href = "michaelyoung.css"/>
<script type="text/javascript" src="work.js"></script>
</head>
<body>
<div>
<h1><img src="Banner.jpeg" alt="Banner" style="width:750px;height:100px;"> </h1>
<div class = 'main'> <!-- Main gray div -->
<h4> Wage Calculator</h4>
<!--border-->
<div class = 'left' > <!-- Left div -->
<p> Other pages </p>
<p><a href="School.html" title="Schools I have attended."> School</a></p>
<p><a href="Contact.html" title="Contact information">Contact</a></p>
<p><a href="Awards.html" title="Awards I've receieved.">Awards</a></p>
<p><a href="Degrees.html" title="Years and Degrees earned.">Degrees</a></p>
</div>
<div class = 'center'> <!-- Center div Took out inline but not working-->
<h3> Salary calculator</h3>
<p> Enter wage per hours: <input type="text" id="textOne" /></p>
<p> Enter hours per week: <input type="text" id="textTwo" /></p>
<input type="button" onclick="getText()" value="Check" />
<p id="change"></p>
</div>
</div>
</div>
</body>
</html>`
我的javascript:
<script>
function getText(){
//access the element with the id 'textOne' and get its value
//assign this value to the variable theText
var theText = document.getElementById('textOne').value;
//alert("Your Hourly Wage is: " + theText);
var hours= document.getElementById('textTwo').value;
//alert("Your hours per week is: " + hours);
var hourlywage=document.getElementById('textOne').value;//saving in hourlywage
var hoursWorked=document.getElementById('textTwo').value;//saving in hoursWorked
var wage = parseInt(hourlywage);//changing to INT
//document.write(wage);
var hours = parseInt(hoursWorked);//changing to INT
//document.write(hours);
var totalpay= (wage * hours)*52;
if(totalpay<20000)
{
document.getElementById("change").innerHTML ="Yearly salary of: $"+totalpay +" is too low thank you!";
}
else if(totalpay>20000 && totalpay<25000)
{
document.getElementById("change").innerHTML ="Yearly salary of: $"+totalpay +" is close lets negotiate!";
}
else
{
document.getElementById("change").innerHTML ="Yearly salary of: $"+totalpay + " is just right!"
}
//document.write(totalpay);
}
</script>
您可以查看是否'工作.js'在外部文件時正在加載?如果您使用[Chrome開發人員工具](https://developers.google.com/web/tools/setup/workspace/setup-devtools),則可以檢查文件是否已成功提供。 – bunnmatt