【发布时间】:2014-08-21 15:45:38
【问题描述】:
我在从 href 链接定位 div 时遇到问题。
我可以使用 div 来做到这一点。例如,我可以使用这样的代码来定位 div。
<div id="nav">
<a href="index1.html">home</a>
<a href="index.php">why</a>
<a href="search.php">a story</a>
<a href="testpage.php">a picture</a>
</div>
它以这个 div 为目标,这是点击特定链接后它会出现的位置:
<div id="content">
</div>
..这个jquery是
<script type="text/javascript">
$(function(){
$('#nav'a).click(function(e) {
$('#content').hide().load( $(this).attr('href') , function(){
$('#content').show()
})
return false
})
})
</script>
但是,我想在不使用 div 的情况下使用此功能,不幸的是,当我尝试在锚点上使用 id“nav”时,我遇到了麻烦,它不起作用,它似乎加载到另一个页面但没有到 div。
下面是我想要的代码结果
<div>
<a id="nav" href="index1.html">home</a>
<a id="nav" href="index.php">why</a>
<a id="nav" href="search.php">a story</a>
<a id="nav" href="testpage.php">a picture</a>
</div>
我怀疑它与这行代码有关,我在谷歌的某个地方发现这个函数中的“a”指的是一个 div,虽然我不太确定
$('#nav a').click(function(e)
提前致谢!
【问题讨论】:
标签: jquery html search href target