简体   繁体   English

contenteditable无法正常工作

[英]contenteditable not working properly

I have an element in my page that is meant to become editable once its parent is double clicked. 我的页面中有一个元素,一旦双击其父元素,该元素将变为可编辑的。 so something like : 所以像:

<div id="parent"><p class="editable"> enter text here </p></div>

and when the #parent is dblclicked I change the attribute contenteditable to true. #parentdblclicked我改变属性contenteditable为true。

now the problem is that there are two things that prevent the user from editing the text once contenteditable is on: 1) the parent has lots of events and other stuff(including draggable and resizable) binded to it. 现在的问题是,一旦启用contenteditable,有两种方法会阻止用户编辑文本:1)父级有很多事件和其他绑定到其上的东西(包括可拖动和可调整大小的东西)。 If I do an unbind() to it, this part gets solved ( but I don't wanna do that ! ) 2) I also use this code to disable text selection in my page : 如果我对它执行unbind() ,则此部分将得到解决(但我不想这样做!)2)我也使用此代码来禁用页面中的文本选择:

function disableSelection(target){
    if (typeof target.onselectstart!="undefined") //IE route
        target.onselectstart=function(){return false}
    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
        target.style.MozUserSelect="none"
    else //All other route (ie: Opera)
        target.onmousedown=function(){return false}
    target.style.cursor = "default"
} 

and I've tried to exclude editable elements using : 并且我尝试使用排除可编辑元素:

disableSelection($(":not(.editable)").get(0));

but it seems to disable everything in the page. 但似乎禁用了页面中的所有内容。 When I get rid of it, it solves the other half of the problem. 当我摆脱它时,它解决了问题的另一半。 so pretty much if I want to enable editing, I have to unbind all the events from the parent, and also get rid of disableSelection, which is not possible for me. 因此,如果要启用编辑功能,我必须取消与父级的所有事件的绑定,并摆脱disableSelection,这对我来说是不可能的。

Does anyone have any idea on how to fix this ? 有谁知道如何解决这个问题? the solution must be easier than what I think, but I think I'm just confusing myself right now ! 解决方案一定比我想的要容易,但是我想我只是在使自己困惑!

jQuery UI .draggable() and .resizable() have a cancel property for which contained elements should not trigger the dragging jQuery UI .draggable()和.resizable()具有cancel属性,对于该属性,所包含的元素不应触发拖动

http://jqueryui.com/demos/draggable/#option-cancel http://jqueryui.com/demos/draggable/#option-cancel

Is it just those two you need to ignore? 只是您需要忽略的那两个吗?

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

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