【问题标题】:onmouseenter and click function doesn't works togetheronmouseenter 和 click 功能不能一起使用
【发布时间】:2013-12-19 08:55:24
【问题描述】:

我在我的应用程序中使用 Meteorjs。在这里,我遇到了一个问题。我有一个锚标签。我必须在onmouseenterclick 事件上调用函数。我所做的是,如果用户click 在锚标记上打开引导框提示对话框以编辑锚标记的文本。如果用户“mouseenter”在锚标记上并在那里停留 3 秒,则调用的函数会显示引导弹出窗口。我的问题是,如果我单击锚标记并在那里停留三个弹出框显示,它会隐藏在锚标记单击事件中打开的引导框对话框。
我的代码是
在元素上输入鼠标时调用的函数。

'mouseenter .edit_name': function (evt, tgt) {
    timer = setTimeout( function() {
            var id=$(evt.currentTarget).data("pk");
            $("#edit_name_"+id).popover({title:"Objective" ,content:Objective})
            $("#edit_name_"+id).popover("show")
            }, 1500);
    }
    },  

鼠标离开功能

'mouseleave .edit_name': function (evt, tgt) {
    $(evt.currentTarget).data("pk");
    $("#edit_name_"+id).popover("hide")
    clearTimeout(timer);
},

点击时调用的函数

'click .edit_name': function (evt, tgt) {
    bootbox.prompt("Module Name",function(arg1,arg2){
}
},

但是当我单击元素并在那里停留 3 秒时,引导框提示消失并显示弹出框。告诉我,如果我单击元素,如何停止显示弹出框。

编辑:
而不是 bootbox.prompt 我尝试了这样的 bootstrap.editable.js

$(".edit_name").editable({
    inputClass: 'input-large',
    url: function (params) {
        Meteor.call("renameItem", params.pk, params.value);

    }
});

但仍然是同样的问题。当弹出窗口显示时,它会隐藏 .editable 输入字段。

【问题讨论】:

  • 顺便说一句,你少了几个; :)
  • 表示使用分号会正常工作吗?
  • 我说的是“顺便说一句”,所以它与您的问题无关,仅与您的编码风格有关。
  • 好的,Thanx Morre,我会改进的。

标签: javascript jquery twitter-bootstrap meteor meteorite


【解决方案1】:

只需检查引导箱是否存在于您的setTimeout 函数中。如果 bootbox 存在,则不要运行 popover 代码。

"mouseenter .edit_name": function () {
  timer = setTimeout( function() {
    if ( !$(".bootbox").length ) {
      $(".edit_name").popover( { title: "Objective", content: Objective } );
      $(".edit_name").popover("show");
    }
  }, 1500);
}

【讨论】:

  • thanx Cuberto,但我不明白如何执行此操作或您建议如何执行此操作?
  • 是的,谢谢@Cuberto。它工作正常。你能告诉我它是如何工作的吗?
  • $(".bootbox") 在 DOM 中搜索类为“bootbox”的元素,这就是 bootbox 的作用。 jQuery 调用返回一个数组,如果没有 bootbox 元素,该数组将为空。 if ( !someArray.length ) 仅表示“如果数组的长度值是假的(在本例中为 0)”。
  • 是的,理解,但它会产生另一个问题。现在它完全阻止了popovers。意思是如果我不点击<a> 标签并在上面输入鼠标 1500 秒或更长时间,它不会显示任何弹出窗口。
  • 你有另一个带有 bootbox 类的元素吗?
猜你喜欢
  • 1970-01-01
  • 2010-10-04
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
  • 2017-06-19
  • 1970-01-01
  • 1970-01-01
  • 2018-12-10
相关资源
最近更新 更多