作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最近尝试制作工作页面来根据按钮显示和隐藏每个元素,但我不知何故缺少一些东西来使这项工作正常进行,或者不知何故它根本不起作用。
当我运行此示例时,前两个“A”链接有效,但第三个无效,有没有办法将其实际分隔到每个元素显示单数的位置,同时隐藏其余元素?
这是我的编码:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<script>
$(document).ready(function(){
$("p").hide(); //to hide all P elem for user to start
$("#hide").click(function(){
$("p#2").show();
$("p#1").hide(); //Yes i tried grouping by selectors
$("p#3").hide(); //and also seperating like this
}); //but both didnt work :(
$("#show").click(function(){
$("p#1").show();
$("p#2").hide();
$("p#3").hide();
});
$("#other").click(function(){
$("p#3").show();
$("p#1").hide();
$("p#2").hide();
});
});
</script>
</head>
<body>
<div>please select a button to begin
<br />
<br />
<p id="1">If you click on the "Hide" button, I will disappear.</p>
<p id="2">If you click on the "Show" button, i will disappear!</p>
<p id="3">yay, another one</p>
<a id="hide">Hide</a>
<a id="show">Show</a>
<a id="third">other</a>
</div>
</body>
</html>
最佳答案
您需要替换它:
$("#other").click(function(){
与:
$("#third").click(function(){
关于javascript - Jquery选择隐藏和显示问题: More than two elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39070639/
我是一名优秀的程序员,十分优秀!