简体   繁体   中英

Separate javascript in to own .js file

You may see a JS below which is now commented which is now copied in all-set.js without two <script> lines.

It was working when I was using the code in head, now it's not.

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="all-set.js" ></script>

    <!--
    <SCRIPT language="javascript" >
    $(function(){

        // add multiple select / deselect functionality
        $("#selectall").click(function () {
          $('.case').attr('checked', this.checked);
        });

        // if all checkbox are selected, check the selectall checkbox
        // and viceversa
        $(".case").click(function(){

            if($(".case").length == $(".case:checked").length) {
                $("#selectall").attr("checked", "checked");
            } else {
                $("#selectall").removeAttr("checked");
            }

        });
    });
    </SCRIPT> 
    -->
</head>

What is your directory structure?

Where is the JS and where is the HTML file?

Are they right besides each other in the same folder?

If yes, try changing src of your script tag like:

<script type="text/javascript" src="./all-set.js" ></script>

Inside the JS file remove the script tags. These don't have to be there:

<SCRIPT language="javascript" >
</SCRIPT> 

Also, as a general rule, always use lower-case tags in HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM