简体   繁体   English

Bootstrap列表组内的链接不起作用

[英]Links inside Bootstrap list-group not working

Here is my code. 这是我的代码。 As you can see is a list-group of anchors that redirect to different sections (here changed to Twitter address in order to test the code) and a final dropdown menu with internal links too. 如您所见,这是一个锚列表组,它们重定向到不同的部分(这里为了测试代码而更改为Twitter地址),还有一个带有内部链接的最终下拉菜单。 You can check it in bootply too. 您也可以在bootply中对其进行检查 And as you can see, the links are not working. 如您所见,链接不起作用。 Even if I take out the dropdown menu, it still doesn't work. 即使我删除了下拉菜单,它仍然无法正常工作。 It does nothing, and I am clueless about why. 它什么都不做,我也不知道为什么。

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <style> .list-group.panel > .list-group-item { border-bottom-right-radius: 4px; border-bottom-left-radius: 4px } .list-group-submenu { margin-left:20px; } </style> <div class="list-group"> <a href="http://twitter.com" class="list-group-item list-group-item-action disabled" id="10_2016" target="_blank"> October 2016 <span class="badge" data-toggle="tooltip" data-container="body" data-original-title="Active news">0</span> <span class="badge badge-gray pull-right" data-toggle="tooltip" data-container="body" data-original-title="Inactive news">0</span> </a> <a href="http://twitter.com" class="list-group-item list-group-item-action" id="9_2016" target="_blank"> September 2016 <span class="badge" data-toggle="tooltip" data-container="body" data-original-title="Active news">2</span> <span class="badge badge-gray pull-right" data-toggle="tooltip" data-container="body" data-original-title="Inactive news">0</span> </a> <!-- Here go more months --> <a aria-expanded="true" href="#SubMenu1" class="list-group-item active" data-toggle="collapse" data-parent="#SubMenu1"> Historic <i class="fa fa-caret-down"></i> <span class="badge">1</span> </a> <div aria-expanded="true" style="" class="list-group-submenu collapse in" id="SubMenu1"> <a href="http://twitter.com" class="list-group-item active" data-parent="#SubMenu1" target="_blank"> 2015 <span class="badge">1</span> </a> <!-- Here go more years --> </div> </div> 

As @MoshFeu and @almostabeginner have proved in the comments, the code works, but it doesn't work in my project. 正如@MoshFeu和@almostabeginner在注释中证明的那样,该代码有效,但在我的项目中不起作用。 Here I add a few more details about the environment of this code and what I've tried: The project is PHP, the html is prepared in a function in a class and echoed inside a column and row in bootstrap. 在这里,我添加了有关此代码的环境以及我尝试过的内容的更多详细信息:该项目是PHP,该html是在一个类的函数中准备的,并在引导程序的列和行内回显。 I have changed the internal URL in href by the twitter URL to be sure the path was not bad. 我已通过Twitter URL更改了href中的内部URL,以确保路径不错。 I have very little js going on on that page. 我在该页面上进行的js很少。 In the console I can't see any malformed html or js errors. 在控制台中,我看不到任何格式错误的html或js错误。 There is some specific styles for that page, but the only styles about links are about their colour. 该页面有一些特定的样式,但是有关链接的唯一样式是关于其颜色的。 So I don't know what else could I try. 所以我不知道我还能尝试什么。

I think it is because you have set target="_blank" , remove that line and it should work. 我认为这是因为您已经设置了target="_blank" ,请删除该行,它应该可以工作。

http://www.bootply.com/VX0dtnLSbF http://www.bootply.com/VX0dtnLSbF

Clearly bootply does not allow new window, I tried 显然bootply不允许新窗口,我试过

onclick="window.open(this.href,'_blank');return false;"

in bootply, and it still did not work, but the link works. 在bootply中,它仍然没有用,但是链接有效。

If you ever want to debug JS I suggest using Chrome "inspect" feature, that will make your life easy. 如果您想调试JS,建议您使用Chrome“检查”功能,这将使您的生活变得轻松。

Edit to add: 编辑添加:

This is the message you get when you click the Twitter link: 这是单击Twitter链接时收到的消息:

Refused to display ' https://twitter.com/ ' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'". 拒绝在框架中显示“ https://twitter.com/ ”,因为祖先违反了以下内容安全策略指令:“ frame-ancestors'self'”。

Simply put, bootply does not allow it, otherwise the link is working perfectly fine. 简而言之,bootply不允许这样做,否则链接可以正常工作。

It was a stupid e.preventdefault in a stupid included file. 这是一个愚蠢的包含文件中的愚蠢的e.preventdefault。 Sorry I made you lose your time with this! 抱歉,我让您为此失去了时间!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM