本文介绍了当我在具有 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 文件内容将被扩展为 (开始和结束)标签的内容.

The src file contents will get expanded as content of <script> (start and end) tag.

如果需要,您可以使用 firebug 进行检查.

You can inspect this with firebug if you want.

这篇关于当我在具有 src 属性的同一个脚本标签中使用 jquery/javascript 代码时,为什么它不起作用&amp;#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 20:06