当我在具有 src 属性的同一个脚本标签中使用 jquery/javascript 代码时,为什么它不起作用' [英] why jquery/javascript code doesn't work when I use it in same script tag with src attribute

查看:20
本文介绍了当我在具有 src 属性的同一个脚本标签中使用 jquery/javascript 代码时,为什么它不起作用'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
带有 src 和内容的脚本标签是什么意思?

我在我的 html 页面中使用了以下内容

I used the following in my html page

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="resources/scripts/jquery-1.8.2.min.js">

$(document).ready(function(){
  alert("ABC");
});
</script>
</head>

<body>
<p>THIS IS MY INDEX PAGE.</p>
</body>
</html>

jquery 在这里不起作用,这意味着在将警报放入其中后我看不到它的任何影响.

The jquery doesn't work here meaning I don't see any effect of it after putting an alert in it.

但是当我放入单独的 <script> 标签时,如下所示,

But when I put in seperate <script> tag like the one below it works,

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="resources/scripts/jquery-1.8.2.min.js">
</script>
<script>
$(document).ready(function(){
  alert("ABC");
});
</script>
</head>

<body>
<p>If you click on me, I will disappear.</p>
</body>
</html>

所以如果有人解释一下?

so if anyone any explain?

推荐答案

这是因为,您使用 javascript 提供了 src 标签.

This is because, you are providing the src tag with the javascript.

src 文件内容将被扩展为

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆