HTML:
<!DOCTYPE html>
<html>
<head>
<script src="adlocationverify.js"></script>
<!--other script and also external css included over here-->
</head>
<body>
<form>
Sales Rep: <input type="text" name="salesrep" required><br>
Customer Name: <input type="text" name="customer" required><br>
Target URL: <input type="text" name="url1" required><br>
Target URL: <input type="text" name="url2"><br>
Target URL: <input type="text" name="url3"><br>
Number of Impressions: <input type="number" name="impressions" min="100000" required><br>
Start Date: <input type="date" name="startdate" required><br>
End Date: <input type="date" name="enddate" required><br>
Geo Target (Optional): <input type="text" name="geo"><br>
Technologies (Optional): <input type="text" name="tags"><br>
Ad Locations: <input type="checkbox" name="top"> Top Leaderboard <input type="checkbox" name="middle"> Middle Leaderboard <input type="checkbox" name="sidebar"> Sidebar<br>
<input type="submit" name="submit" onClick="validateadlocation()">
</form>
</body>
</html>
JS:
<script>
function validateadlocation()
{
var checkboxs=document.getElementsByName("top middle sidebar");
var okay=false;
for(var i=0,l=checkboxs.length;i<l;i++)
{
if(checkboxs[i].checked)
{
okay=true;
}
}
if(okay)alert("Thank you for checking a checkbox");
else alert("Please check a checkbox");
}
</script>
JavaScript 在嵌入 HTML 时可以工作,但在尝试从外部文件调用它时则无法工作。
最佳答案
js 文件不应包含 <script>
和</script>
标签。标签只能包含在 html 文件中。
关于javascript - HTML不调用外部JS文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25729717/