【问题标题】:Why alert from external JS not appearing [duplicate]为什么没有出现来自外部 JS 的警报 [重复]
【发布时间】:2015-08-29 18:48:16
【问题描述】:

为什么以下 HTML 中没有出现警报?

我的 HTML

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="a.js"/>
</head>
<body>

</body>
<html>

a.js

alert("hello");

【问题讨论】:

标签: javascript


【解决方案1】:

你不能有一个自结束脚本标签。将脚本标签更改为:

<script src="a.js"></script>

【讨论】:

    【解决方案2】:

    script 标签不能自动关闭。试试这个:

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <script src="a.js"></script>
    </head>
    <body>
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多