如果您明白我的意思,我想在 jQuery 选项卡上创建一个指向 anchor 的链接。我有一个页面,上面有两个选项卡 #idTab1 和 #idTab2。我在这里使用 Sean Catchpole 的 jQuery idTabs... http://www.sunsean.com/idTabs/
这是我所拥有的代码的模拟版本...
<div class="usual">
<ul class="idTabs">
<li><a name="idTab1" href="#idTab1" class="selected">Terms of Use</a></li>
<li><a name="idTab2" href="#idTab2">Privacy Policy</a></li>
</ul>
<div class="handbook" id="idTab1">
<p>Some content here...</p>
</div>
<div class="handbook" id="idTab2">
<p>Some content here...</p>
</div>
</div>
我想要实现的是两个链接,一个用于#idTab1,第二个用于#idTab2。我在底部页脚中创建了以下内容...
<div class="subfooter">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><a href="<?php echo url('/content/legal#idTab1');?>">Terms of Use</a> | <a href="<?php echo url('/content/legal#idTab2');?>">Privacy Policy</a><br/>
<small><?php
$mtime = explode(' ', microtime());
$totaltime = $mtime[0] + $mtime[1] - $starttime;
printf('Page generated in %.3f seconds.', $totaltime);
?></small></td>
</tr>
</table>
</div>
上面的链接确实有效,页面打开,但 legal#idTab2 链接到第一个选项卡。如果您提供任何提示或帮助,我将不胜感激。
干杯。
最佳答案
jquery 的功能是先更改选项卡,然后再定位到选项卡。
<script>
function js_tabs_link(tabnum,anchorLink){
$('#tabs_container_id').tabs('option', 'selected', tabnum);
//tabnums start from 1 not 0
window.location = "#"+anchorLink;
}
</script>
并使用
为您的链接调用脚本<a href='javascript:js_tabs_link("3","about_us")'>about us</a>
关于jquery - 链接到另一个页面上的 anchor jQuery 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10817116/