gpt4 book ai didi

jquery - jQuery 新手 - 为什么这不起作用?

转载 作者:行者123 更新时间:2023-12-01 08:09:01 26 4
gpt4 key购买 nike

这真的很基本,所以提前抱歉不得不寻求帮助:o

我已经设置了一个简单的页面来使用 jQuery,但我无法使用简单的显示/隐藏功能。

这是我的代码..

<html>
<head>
<title>Testing Javascript/jQuery</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("div p").hide();
});

$("show").click(function(){
$("div p").show()
});

$("hide").click(function(){
$("div p").hide()
});
</script>
</head>
<body>
<button id='hide'>Click to hide the text</button>
<button id='show'>Click to show the text</button>
<div><p>you can't see me!</p></div>
</body>
</html>

Chrome 开发者工具没有给出错误,所以我不知道该去哪里查找。

文本最初是隐藏的,但显示和隐藏按钮没有任何作用。

最佳答案

替换

$("show").click(function(){

$("#show").click(function(){

这样 jQuery 就会查找 id 为 show 的元素(当然对于 $("hide") 也是如此)。

关于jquery - jQuery 新手 - 为什么这不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14799461/

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