gpt4 book ai didi

javascript - 为什么当我在具有 src 属性的同一脚本标记中使用 jquery/javascript 代码时,它不起作用

转载 作者:行者123 更新时间:2023-11-28 11:13:23 24 4
gpt4 key购买 nike

Possible Duplicate:
What does a script-Tag with src AND content mean?

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

<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 在这里不起作用,这意味着在放入警报后我看不到它的任何效果。

但是当我单独输入<script>时标签就像下面的标签一样有效,

<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>

有谁解释一下吗?

最佳答案

来自 w3schools:

http://www.w3schools.com/tags/tag_script.asp

“注意:如果存在“src”属性,则该元素必须为空。”

当您使用 script 标签时,您可以使用 src 属性或在标签内提供源代码,但不能同时提供两者。

关于javascript - 为什么当我在具有 src 属性的同一脚本标记中使用 jquery/javascript 代码时,它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13016496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com