【问题标题】:Hiding id of another page when read more button clicked单击阅读更多按钮时隐藏另一个页面的ID
【发布时间】:2014-01-22 06:02:09
【问题描述】:

我有一个带有描述和阅读更多按钮的页面(4 个相同的 div)。当点击阅读更多按钮时,它将指向显示所有 4 个 div 的完整描述的页面。当单击特定 div 的更多内容时,我想指向包含所有内容的页面,但它应该只显示该特定 div 的完整描述并隐藏其他 div 描述

HTML 代码

一个.html

<html>
<head>
<script type="text/javascript">
$(document).ready(function()
$(".a1 a").click(function()
$("#a2_bio").hide();
$("#a3_bio").hide();
$("#a4_bio").hide();
});
});
</script>
</head>

<body>
<style type="text/css">
p
{
font-size:12px;
font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
text-align:center;
}
.a1, .a2, .a3, .a4
{
width:300px;height:200px;float:left;
margin-left:30px;
border:1px dotted #CCCCCC;
padding:1px;
background:#CCC;
}
.images
{
width:100px;
height:75px;
margin:0 auto;
border:1px #666 solid;
margin-top:30px;
background:#C36;    
}

.a1 a, .a2 a, .a3 a, .a4 a
{
float:right;
margin-right:10px;
width:75px;
height:20px;
font-size:11px;
color:#060;
}
</style>

<div class="a1">
<div class="images"> </div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="two.html#a1_bio"> Read more </a>
</div>

<div class="a2">
<div class="images"> </div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="two.html#a2_bio"> Read more </a>
</div>

<div class="a3">
<div class="images"> </div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="two.html#a3_bio"> Read more </a>
</div>

<div class="a4">
<div class="images"> </div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="two.html#a4_bio"> Read more </a>
</div>

</body>
</html>

两个.html

<html>
<body>
<style type="text/css">
#a1_bio, #a2_bio, #a3_bio, #a4_bio
{
width:800px;
height:200px;
background:#CCC; 
border:#666 1px solid;
margin-bottom:20px !important;
float:none;
margin:0 auto;
}

#a1_bio p, #a2_bio p, #a3_bio p, #a4_bio p
{
font-size:12px;
font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;   
}
</style>
<div id="a1_bio">
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

<div id="a2_bio">
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

<div id="a3_bio">
 <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

<div id="a4_bio">
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

</body>
</html>

【问题讨论】:

  • 如果回答符合您的要求,您可以接受,以便其他用户获得帮助。
  • 更新了我的代码检查...

标签: javascript jquery html css


【解决方案1】:

你可以尝试在ready上使用以下JS(在two.html中,默认隐藏所有div,在one.html中使用url,如:two.html?url=a2_bio):

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,    
    function(m,key,value) {
      vars[key] = value;
    });
    return vars;
}
var divId = getUrlVars()["url"];
$('#'+divId).show();

【讨论】:

  • 我可以知道您遇到了什么错误或您尝试了什么吗?
【解决方案2】:

试试这个代码:

DEMO

JS

 var hashes = window.location.hash;
 $(hashes).show();

CSS

 #a1_bio, #a2_bio, #a3_bio, #a4_bio
    {
    width:800px;
    height:200px;
    background:#CCC; 
    border:#666 1px solid;
    margin-bottom:20px !important;
    float:none;
    margin:0 auto;
    display:none;
    }

【讨论】:

  • 我需要把JS放在two.html的ready函数里面吗?
猜你喜欢
  • 2011-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-02
  • 2020-12-20
  • 2011-08-15
相关资源
最近更新 更多