简体   繁体   English

将JavaScript单独放入自己的.js文件

[英]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. 您可能会在下面看到一个JS,该JS现在已注释,现在已复制到all-set.js没有两行<script>行。

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? JS在哪里, HTML文件在哪里?

Are they right besides each other in the same folder? 它们在同一文件夹中彼此相邻吗?

If yes, try changing src of your script tag like: 如果是,请尝试更改script标记的src ,例如:

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

Inside the JS file remove the script tags. 在JS文件中,删除脚本标签。 These don't have to be there: 这些不必在那里:

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

Also, as a general rule, always use lower-case tags in HTML. 同样,通常,在HTML中始终使用小写标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否应该在单独的.js文件中定义网页的每个Javascript函数? - Is each Javascript function of a webpage supposed to be defined in its own separate .js file? 将 javascript 添加到单独的文件 .js - Add javascript to separate file .js 简洁的JavaScript-找不到单独的JS文件 - Unobtrusive JavaScript - Separate JS File Not Found 应该所有的javascript进入一个单独的js文件 - should all javascript go into a separate js file 在单独的js文件中扩展bootstrap对话框javascript - Extending bootstrap dialog javascript in separate js file 单独的JS文件中的Javascript getElementById,用JavaScript编写的src - Javascript getElementById in separate JS file, src written with javascript 如何使用全局延迟js文件和单独的独立javascript文件 - How to use a global deferred js file and a separate independant javascript file 如何将 javascript function(写在 .cshtml 文件中)覆盖到单独的 .js 文件中 - How to override a javascript function (written in a .cshtml file ) into a separate .js file HtmlPage.Window.Invoke在单独的js文件中不适用于javascript函数 - HtmlPage.Window.Invoke not working for javascript function in separate js file 是否可以将Javascript代码与Riot Js中的标记文件分开? - Is it possible to separate the javascript code from the tag file in Riot Js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM