这是我的 HTML 文件的内容:
<!DOCTYPE html>
<!-- The above DOCTYPE declaration tells the browser that this page conforms to HTML 5 standards -->
<head>
<meta http-equiv="author" content="Chris" />
<link href="jquery.css" type="text/css" rel="stylesheet" />
</script>
<script src="js/jquery-3.3.1.min.js">
</script>
<script>
$(document).ready(function() {
$('#message').hide();
});
</script>
</head>
<body>
<p id="message">Hello World!</p>
</body>
</html>
我有一个名为 jquery.js 的文件,它是 jQuery 3.3.1 的缩小版本,它保存在我的 HTML 文件和 CSS 文件所在的文件夹 js 中。在本文档中,我尝试使用 hide() 函数隐藏 ID 为 message 的段落,但是当我在 Google Chrome 浏览器中打开该文件时,该段落仍然存在。
注意:显然,我对 JavaScript 和 jQuery 库的实现很陌生。
最佳答案
好的。所以我明白发生了什么事。我正在从一本书中学习 JavaScript,这本书说,当您将 HTML 文件链接到 JavaScript 文件时,将版本号和“min”扩展名包含到 HTML 文件中,即使它不是正确的文件名。由于我的 jQuery 库是 jquery.js,我只是删除了版本号和“min”扩展名。一旦我这样做了,根据 hide() 函数,该段落就消失了。谢谢大家的回复。这只是书和我的大脑之间无法沟通的问题。
<!DOCTYPE html>
<!-- The above DOCTYPE declaration tells the browser that this page conforms to HTML 5 standards -->
<head>
<meta http-equiv="author" content="Chris" />
<link href="jquery.css" type="text/css" rel="stylesheet" />
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
$('#message').hide();
console.log($.fn.jquery);
});
</script>
</head>
<body>
<p id="message">Hello World!</p>
</body>
</html>
关于javascript - jQuery 选择器隐藏功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51435563/