我想使用 a href
将 1 个 div 替换为另一个链接和 jquery。这是我的设置。
<div id="parent">
<div class="child1">Child 1 Contents</div>
<div class="child2">Child 2 Contents</div>
</div>
<div id="replacepagelinks">
<a href="#1">Replace Child 1 with Child 2</a>
<a href="#2">Replace Child 2 with Child 1</a>
</div>
有谁知道如何使用 jquery 完成此操作?我也想要<a href=#1"></a>
选中时消失,<a href="#2"></a>
如果可能的话出现,反之亦然?
最佳答案
如果你想隐藏基于被点击元素的内容,你可以尝试以下方法:
$(document).ready(function(){
$('#replacepagelinks a').click(function(){
$(this).hide().siblings().show()
var w = this.hash.replace('#', '');
$('#parent div.child'+w).show().siblings().hide()
})
})
关于javascript - 用 jquery 替换 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12929040/