简体   繁体   English

当我在firefox浏览器下点击它时,contenteditable触发模糊事件

[英]contenteditable is triggering blur event when I click on it under firefox browser

I have a contentEditable DIV 我有一个contentEditable DIV

<div id="content" contenteditable="true">

  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.

</div>

with the following javascript code : 使用以下javascript代码:

$(document).ready(function(){

    var obj = {

        func1: function(){

            $("#content").on("click", function(){
                alert("click");
            });

            $("#content").on("blur", function(){
                alert("blur");
            });

        }

    }

    function execute(obj){

        obj.func1();

    }


    execute(obj);


});

Here is the jsfiddle : http://jsfiddle.net/mody5/b84708c1/ 这是jsfiddle: http//jsfiddle.net/mody5/b84708c1/

The code is supposed to alert "click" when I click the contentEditable div and to alert "blur" when I click out of the contentEditable div, but in FIREFOX when I click it trigger "blur" event too ! 当我单击contentEditable div时,代码应该警告“click”,当我点击contentEditable div时警告“模糊”,但是当我点击它时FIREFOX也触发“模糊”事件!

Is this a bug ? 这是一个错误吗? how I can solve this ? 我怎么能解决这个问题?

In firefox alert() will trigger the blur event, because it will change the focus into the alert box. 在firefox中, alert()会触发模糊事件,因为它会将焦点更改为警告框。 And thus trigger the blur event. 从而触发模糊事件。

In your code, just change alert("click"); 在您的代码中,只需更改alert("click"); into something else.. like console.log("click"); 进入别的东西..比如console.log("click"); and it will work. 它会起作用。

Note: In chrome it works because the alert() function works in different ways for firefox and chrome. 注意:在chrome中它可以工作,因为alert()函数以不同的方式为firefox和chrome工作。

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

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