2015-11-18 134 views
0

我有一个不支持HTML文件的外部JavaScript,我不知道为什么Firebug没有报告任何失败。 如果我在我的HTML中运行JS,它的工作原理非常完美。外部JavaScript不起作用

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> 
+4

我没有看到jQuery加载,使用它之前加载jQuery,即之前actions.js – Tushar

+0

哦,我的错误,现在很好,非常感谢你。 – Faculty

+0

然而'如果我在我的HTML中运行JS,它完美的工作 –

回答

0

您可以用下面的代码中插入的jQuery:

<script src="jquery_file.js" type="text/javascript"></script> 

,或者你可以从他们的主页下载jQuery的文件,并引用下载的文件在文档中。这里是你可以下载jQuery的链接:https://jquery.com/download/

0

您需要先加载了jQuery。

<script src="your_jquery_file.js" type="text/javascript"></script> 
<script language="javascript" type="text/javascript" src="./action.js"></script>