简体   繁体   English

使用link_to之后添加了额外的末端锚标记

[英]Additional end anchor tags added after using link_to

For some reason rails is generating additional anchor tags after I use link_to inside an HTML anchor tag. 由于某些原因,在HTML锚标记内使用link_to之后,rails会生成其他锚标记。 Is this HTML design or rails constrain.? 这是HTML设计还是Rails约束?

<li>
                <a id="user-menu" href="#">
                    <%=current_user.first_name%>
                    <div id="bubblemenu" class="lotusBubble-content" style="display:none"> 
                      <ul>
                          <li><%= link_to "My Profile", current_user %></li>
                          <li>My Bookmarks</li>
                          <li>My Active</li>
                          <li>My Expired</li>
                      </ul>
                    </div>
                </a>
            </li>

This generates a HTML like this 这样会生成这样的HTML

            <li>
                <a id="user-menu" href="#">Srikanth</a>
                  <div id="bubblemenu" class="lotusBubble-content" style="display:none">
                              <a id="user-menu" href="#"> </a>
                              <ul>
                                    <a id="user-menu" href="#">
                                    </a>
                                    <li><a id="user-menu" href="#"></a><a href="/user.1">My Profile</a></li>
                                    <li>My Bookmarks</li>
                                    <li>My Active</li>
                                    <li>My Expired</li>
                              </ul>

why is there so anchor tags added automatically ? 为什么会自动添加锚标记?

这是由于您使用的是link_to指令,该函数在执行时会自动创建一个锚点ta

Just saw this restriction. 刚看到这个限制。 Anchor inside an anchor is not permitted as per HTML standards. 根据HTML标准,锚内的锚是不允许的。 If at all something like that occurs, then the browsers atomically ends the outer anchor 如果发生类似的事情,那么浏览器会自动终止外部锚点

http://www.w3.org/TR/html401/struct/links.html#h-12.2.2 http://www.w3.org/TR/html401/struct/links.html#h-12.2.2

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

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