jquery - UL LI 内的 anchor 破坏了功能

标签 jquery css twitter-bootstrap

当用户将鼠标悬停在 <li> 上时,我正在使用悬停库创建动画。

这是一个示例:

<ul id="da-thumbs" class="da-thumbs">
        <li>
            <a href="#">
                <img src="http://placehold.it/350x150" />
                <div>
                    <span>My Muse by Zachary Horst</span>
                </div>
            </a>
        </li>
...
</ul>

这是工作 fiddle - http://jsfiddle.net/95Lsafhe/

到这里一切都很好。

但是,一旦我在 <span> 下面添加一个 anchor , ,一切都只是折腾。

<ul id="da-thumbs" class="da-thumbs">
        <li>
            <a href="#">
                <img src="http://placehold.it/350x150" />
                <div>
                    <span>My Muse by Zachary Horst</span>
                     <a href="#" class="btn btn-default">Add button</a>
                </div>
            </a>
        </li>
...
</ul>

http://jsfiddle.net/95Lsafhe/1/

我不确定是什么破坏了功能?我只想当使用悬停在 <li> 上时在跨度下方显示 anchor 按钮.

更新:从评论中,我了解到一个 anchor 不能嵌套在另一个 anchor 中。我想要一个直接位于跨度下方的 anchor 。但是,如果外部 anchor 被删除/删除,我确定。你能告诉我如何更改我的 css/代码来实现这一点吗?跨度和按钮必须仅在悬停时可见。

最佳答案

WHat you are doing is wrong you cannot nest html anchor tag It is invalid HTML.

So, by definition, the behaviour is undefined.

Changed Demo

只需将 anchor 标记放在第一个标记下方

<a href="#">
            <img src="http://placehold.it/350x150" />
            <div>
                <span>My Muse by Zachary Horst</span>

            </div>
        </a>
<a href="#" class="btn btn-default AddAnchor">Add button</a>

编辑:-

Work Around you can use span inside the div and emulate the function of anchor tag by firing a click event and inside it use jQuery.get() Method to make HTTP GET Request

Demo with Anchor tag emulated with span

关于jquery - UL LI 内的 anchor 破坏了功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31529973/

相关文章:

javascript - jQuery Accordion 不工作

javascript - 加载视频后页面不会重新加载

html - 如何将品牌、链接和 facebook 链接放在同一行? Bootstrap 3

html - 为什么背景图像没有出现在我的 <div> 中?

jquery - 如何限制两个选择选项匹配某个值?

javascript - 如何追加多个元素JQuery

javascript - 语义 UI 模态对话框未正确关闭

ios - 横向 View 的媒体查询

html - 获得焦点时为父元素应用样式

css - 我们应该将内联 css 应用于 Bootstrap 列吗?