Php 用CodeIgniter锚定到一个部分

Php 用CodeIgniter锚定到一个部分,php,codeigniter,anchor,Php,Codeigniter,Anchor,我正在尝试创建页面元素的锚。有一个选项卡界面。在html中,我可以看到它们的链接如下: http://example.com/index.php/service#tab-1 http://example.com/index.php/service#tab-2 http://example.com/index.php/service#tab-3 http://example.com/index.php/service#tab-4 所以我有4个div,id为tab-1,tab-2等 如何从另一个视

我正在尝试创建页面元素的锚。有一个选项卡界面。在html中,我可以看到它们的链接如下:

http://example.com/index.php/service#tab-1
http://example.com/index.php/service#tab-2
http://example.com/index.php/service#tab-3
http://example.com/index.php/service#tab-4
所以我有4个div,id为tab-1,tab-2等

如何从另一个视图文件创建锚定到它们?当我尝试这个:

<a href="<?=site_url();?>/service#tab-1">give it a try</a>

它进入页面/服务,但不关注表1。它在纯html上工作,但我不能用codeigniter


谢谢你的帮助

您需要在页面中放置
#tab-1
等的目标。因此,在您的div中,您需要包含一个命名锚,例如:

<a name="tab-1"></>


这将导致页面跳转到此元素。

我刚刚在CodeIgniter上尝试了相同的方法,效果很好,因此我建议再次检查您的ID是否正确。除此之外,试试看

<a href="<?=site_url('/service#tab-1');?>">give it a try</a>


查看此线程:如果我没有弄错的话,使用ID而不是名称似乎是公认的方法
<a href="<?=site_url('/service');?>#tab-1">give it a try</a>