满意的,不能正常工作

时间:2012-08-23 16:06:04

标签: javascript jquery contenteditable

我的页面中有一个元素,一旦双击它的父级,它就会变得可编辑。所以像:

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

#parentdblclicked时,我将属性contenteditable更改为true。

现在的问题是,有两件事阻止用户在满足条件时编辑文本: 1)父母有很多事件和其他东西(包括可拖动和可调整大小)绑定到它。如果我对它进行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"
} 

我尝试使用以下方法排除可编辑元素:

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

但它似乎禁用了页面中的所有内容。当我摆脱它时,它解决了问题的另一半。 所以,如果我想启用编辑,我必须取消绑定父节点中的所有事件,并且还要摆脱disableSelection,这对我来说是不可能的。

有没有人知道如何解决这个问题?解决方案必须比我想象的更容易,但我想我现在只是在困惑自己!

1 个答案:

答案 0 :(得分:1)

jQuery UI .draggable()和.resizable()有一个cancel元素,其中包含的元素不应该触发拖动

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

这只是你需要忽略的那两个吗?

相关问题