外部 JavaScript 不起作用
External JavaScript don't work
我有一个外部 JavaScript,它在我的 HTML 文件中不起作用,我不知道为什么 Firebug 没有报告任何故障。
如果我 运行 我的 HTML 中的 JS 完美运行。
action.js
$( document ).ready( function(){
var ochk1 = $("input[type='checkbox'][id='oose']");
var ochk2 = $("input[type='checkbox'][id='ov']");
var ochk3 = $("input[type='checkbox'][id='op']");
ochk1.on('change', function(){
ochk2.prop('checked',this.checked);
ochk3.prop('checked',this.checked);
});
});
和我的 html
test.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<style type="text/css">
@import url("style.css");
</style>
<script language="javascript" type="text/javascript" src="./action.js"></script>
</head>
<body>
<div>
<div class="box">
<input type="checkbox" id="oose">
OOSE
</div>
<div class="bs">
V
<input type="checkbox" id="ov">
</div>
<div class="bs2">
P
<input type="checkbox" id="op">
</div>
</div>
</body>
</html>
您需要先加载 jQuery。
<script src="your_jquery_file.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="./action.js"></script>
您可以使用以下代码插入jquery:
<script src="jquery_file.js" type="text/javascript"></script>
或者您可以从他们的主页下载 jquery 文件并在您的文档中引用下载的文件。这里是 link 可以下载 jquery 的地方:https://jquery.com/download/
我有一个外部 JavaScript,它在我的 HTML 文件中不起作用,我不知道为什么 Firebug 没有报告任何故障。 如果我 运行 我的 HTML 中的 JS 完美运行。
action.js
$( document ).ready( function(){
var ochk1 = $("input[type='checkbox'][id='oose']");
var ochk2 = $("input[type='checkbox'][id='ov']");
var ochk3 = $("input[type='checkbox'][id='op']");
ochk1.on('change', function(){
ochk2.prop('checked',this.checked);
ochk3.prop('checked',this.checked);
});
});
和我的 html test.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<style type="text/css">
@import url("style.css");
</style>
<script language="javascript" type="text/javascript" src="./action.js"></script>
</head>
<body>
<div>
<div class="box">
<input type="checkbox" id="oose">
OOSE
</div>
<div class="bs">
V
<input type="checkbox" id="ov">
</div>
<div class="bs2">
P
<input type="checkbox" id="op">
</div>
</div>
</body>
</html>
您需要先加载 jQuery。
<script src="your_jquery_file.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="./action.js"></script>
您可以使用以下代码插入jquery:
<script src="jquery_file.js" type="text/javascript"></script>
或者您可以从他们的主页下载 jquery 文件并在您的文档中引用下载的文件。这里是 link 可以下载 jquery 的地方:https://jquery.com/download/