简体   繁体   中英

Setting contenteditable on double click - IE does not allow editing unless clicked one more time

Basically, I set contentEditable to true on double click. In IE 8,9,10 it does not have focus, eg typing to not change anything, and you have to click third time to acquire the focus. In Chrome it works as expected (you double click and can start typing) Here is the minimal jsfiddle demonstrating the problem (using mootools).

$('dummy').addEvent('dblclick', function(){
    $('dummy').setProperty('contentEditable', true);
    $('dummy').focus();
});

If it's on any importance, the clicked element is an absolutely positioned div.

How this can be fixed?

IE is... IE.

Try this:

$('dummy').addEvent('dblclick', function () {
    this.setProperty('contentEditable', true);
    this.blur();
    this.focus();
});

Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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