尝试在同一页面的所有段落中添加(查看更多)但是当我多次添加代码时,它仅在一个段落中起作用有帮助吗?
function showHide(shID) {
if (document.getElementById(shID)) {
if (document.getElementById(shID+'-show').style.display != 'none') {
document.getElementById(shID+'-show').style.display = 'none';
document.getElementById(shID).style.display = 'block';
}
else {
document.getElementById(shID+'-show').style.display = 'inline';
document.getElementById(shID).style.display = 'none';
}
}}
代码
<p>
<a href="#" id="example-show" class="showLink" onclick="showHide('example');">See more...</a>
</p>
<div id="example" class="more">
<p>Extra words.....</p>
<p><a href="#" id="example-hide" class="hideLink" onclick="showHide('example');">Hide.</a>
</p>
</div>
CSS
.more {
padding:0 3px 0 0;
display: none;
border: 1px solid #666;
}
a.showLink, a.hideLink {
text-decoration: none;
color: #36f;
padding-left: 8px;
background: transparent url('down.gif') no-repeat left;
}
a.hideLink {
background: transparent url('up.gif') no-repeat left;
}
a.showLink:hover, a.hideLink:hover {
border-bottom: 1px dotted #36f;
}
只有我可以使用一次。
如何在同一页面中多次使用它?