简体   繁体   中英

input textarea select conflict with mousedown event

Im stuck in a strange problem, I have elements with say class .element , and some of them are divs containing text, and when they get double clicked ContentEditable attribute becomes true so the user can edit the text and a class named disabled is added to the element being edited. The reason for it is that .element has a mousedown event attached to it as well, and I don't want the event being fired when the element is being edited because the user might want to select the text or re-position the caret. To do so I've added something like this to my mousedown event :

if(element.hasClass("disabled")) return false;

which doesnt work, but if I get rid my mousedown event, and use "click" event instead, it works perfectly. what should I do ?

edit: here is an example " http://jsfiddle.net/wqKke/ ... if you notice when you double click each element they become editable, but you're not able to select or reposition the caret in the element, so it's really hard to edit that element, but if you change the mouseover to click, the problem is solved !

You have a return false; in the mousedown event, which is what prevents the user from selecting text or moving the caret. I don't see a reason to have the return false; as all you want to do is prevent the code after from executing, which you can do by return ing anything.

So even this would suffice:

if(element.hasClass("disabled")) return;

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