我有HTMl文檔,這是單選按鈕,並在外部文件filename.js 和我在裏面使用的功能。 它是正確的在任何可能的方式,從書中複製貓,但它不會工作時, 執行html文件。我已將.html文件和filename.js文件放入新文件夾中,其中只有兩個文件。這裏似乎有什麼問題,我喜歡一些建議。一個外部文件的Javascript放置
authorx。
我有HTMl文檔,這是單選按鈕,並在外部文件filename.js 和我在裏面使用的功能。 它是正確的在任何可能的方式,從書中複製貓,但它不會工作時, 執行html文件。我已將.html文件和filename.js文件放入新文件夾中,其中只有兩個文件。這裏似乎有什麼問題,我喜歡一些建議。一個外部文件的Javascript放置
authorx。
我不能完全沒有看到一些代碼,但從HTML文件執行單獨的JavaScript文件的標準方式是使用腳本標記。這裏更多的信息:http://www.w3schools.com/tags/tag_script.asp
在你的情況,標籤看起來像
<script src="filename.js"></script>
我的代碼看起來像這樣
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> Radio Button </title>
<script type= "text/javascript" src = "radio_plane.js" >
</script>
<body>
<h4> Cessna single-engine airplane description </h4>
<form id="myform" action="">
<p>
<label><input type="radio" name="planebutton" value="152" onclick="action(152);" />
Model 152 </label>
<br />
<label><input type="radio" name="planebutton" value="172" onclick="action(172);" />
Model 172 (Skyhawk)</label>
<br />
<label><input type="radio" name="planebutton" value="182" onclick="action(182);" />
Model 182</label>
<br />
<label><input type="radio" name="planebutton" value="210" onclick="action(210);" />
Model 210 (Centurian) </label>
<br />
</p>
</form>
</body>
</html>
and javascript file
function action(plane)
{
switch(plane)
{
case 152:
alert("A small two-place airplane for flight training");
break;
case 172:
alert("The Smaller of two four-plane airplanes");
break;
case 182:
alert("The larger of two four-place airplanes");
break;
case 210:
alert("A six-place high-performance airplane");
break;
default:
alert("Error in JavaScript function planeChoice");
break;
}
}
代碼示例應該在您的原始問題中,而不是在單獨的答案中。考慮編輯您的原始問題以包含此代碼。 – Ectropy
你可以張貼一些代碼呢? – Mike
請張貼一些代碼示例 –