javascript - 为什么悬停事件不能与 Bootstrap 选项卡上的 jquery 方法一起使用?

标签 javascript jquery html twitter-bootstrap tabs

关于bootstrap tabs documentation page我尝试了以下代码:

$(".nav-tabs > li > a").on("hover focus", function(){ 
  alert();
});

当选项卡获得焦点时会显示警报,但当我将鼠标悬停在选项卡上时不会显示警报。我的问题是:

  • 为什么悬停事件不能与 Bootstrap 选项卡上的 on jquery 方法一起使用?

最佳答案

这不起作用的两个原因

1) alert() 在网站上被禁止

2) .on('hover') 已弃用。

Deprecated in jQuery 1.8, removed in 1.9: The name "hover" used as a shorthand for the string "mouseenter mouseleave". It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions.

尝试此代码以查看您想要的结果。

$(".nav-tabs > li > a").on("mouseover focus", function(){ 
  console.log("hello");
});

这确实有效,只是不适用于 alert 方法。尝试使用替代方法,在网站允许的屏幕上弹出一些内容。

关于javascript - 为什么悬停事件不能与 Bootstrap 选项卡上的 jquery 方法一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40409629/

相关文章:

jquery - 构建没有服务器端 Web 技术(如 asp.net、asp.net mvc 等)的 Web 应用程序

javascript - 用纯 JavaScript 编写 jQuery 语句

php - 使用 php 和 html 选择框过滤 SQL 查询

javascript - 将屏幕坐标转换为页面坐标

javascript - 遍历 List 元素以构建一个数组以在 AJAX 请求中传递

javascript - 将目标空白添加到 JavaScript 生成的链接

javascript - 使用 styleTween 进行带百分比的 d3 过渡

javascript - 使用 Passport 在 Express 的 POST 中传递参数

javascript - 如何在服务器端获取客户端变量的值

html - 如何在 anchor 标签的标题属性中添加图片标签?