我必须用p
隐藏一个id=2
,但是我没发现p
和id=2
都不会被隐藏!
我的错误是什么
代码:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("p.2").hide();
});
$("#show").click(function(){
$("p.2").show();
});
});
</script>
</head>
<body>
<p id="2">If you click on the "Hide" button, I will disappear.</p>
<button id="hide">Hide</button>
<button id="show">Show</button>
</body>
答案 0 :(得分:1)
您正试图显示和隐藏类别为2的<p>
元素,但您只有一个{em> ID 2的<p>
元素。应该是这样的:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("p#2").hide();
});
$("#show").click(function(){
$("p#2").show();
});
});
</script>
</head>
<body>
<p id="2">If you click on the "Hide" button, I will disappear.</p>
<button id="hide">Hide</button>
<button id="show">Show</button>
</body>
答案 1 :(得分:0)
这是使用 class TForm
p
2
应该是$("p.2").hide();
的 id
#