我的外部javascript JQUERY没有'不适用于chrome或其他浏览器

My external javascript JQUERY doesn't work on chrome or other browser

本文关键字:适用于 不适用 chrome 浏览器 其他 javascript 外部 JQUERY 没有 我的      更新时间:2023-09-26

html文件是

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>My Website /title>
<link rel='stylesheet' type='text/css' href='stylesheet4.css'>
<link rel='stylesheet' type='text/css' href='http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css'>
</head>
<body>
<!--other code -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="script3.js"></script>
</body>
</html>

我的script3.js文件是

$(function(){
  "use strict";
    $('#checkOut').click(function(){
        var time=2;
         alert("The time is "+time+"!");
    // more code 
});

我怎么把它联系错了?当我使用jfiddle测试我的代码时,当我点击按钮时,警报就会工作。然而,我使用的是记事本++,我不确定我做错了什么。

我看到了两个问题,还有一些问题需要解决。

在script3.js中,缺少一个});。所以应该是:

$(function(){
  "use strict";
    $('#checkOut').click(function(){
        var time=2;
        alert("The time is "+time+"!");
        // more code 
    });
});

标题标签格式不正确:

<title>My Website /title>

需要:

<title>My Website </title>

编辑:示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>My Website </title>
        <link rel='stylesheet' type='text/css' href='stylesheet4.css'>
        <link rel='stylesheet' type='text/css' href='http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css'>
    </head>
    <body>
        <!--other code -->
        <input type="button" id="checkOut" value="check out" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="script3.js"></script>
    </body>
</html>