簡體   English   中英

外部JavaScript不起作用

[英]External JavaScript don't work

我有一個無法在HTML文件中使用的外部JavaScript,而且我不知道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文件,並在文檔中引用下載的文件。 這是您可以下載jquery的鏈接: https : //jquery.com/download/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM