简体   繁体   English

在内容可编辑div中选择jquery draggable中的文本

[英]Select text in Content editable div which is jquery draggable

I have a contenteditable div which is a child of another div which is made into a draggable element using jquery. 我有一个contenteditable div,它是另一个div的孩子,使用jquery制作成可拖动的元素。

<div id="draggable">
  <div id = "editable" contenteditable="true"/>
</div>

$('#draggable').draggable({revert:true});

The problem I am facing is that none of the default mouse actions like selecting pieces of text etc are disabled. 我面临的问题是没有禁用默认鼠标操作,如选择文本片段等。 Moreover if I try to select some text it just drags the whole div. 此外,如果我尝试选择一些文本,它只会拖动整个div。 I tried some thing like this: 我试过这样的事情:

$('#editable').mousemove(function(event){
  event.stopPropogation();
})

but this just prevents any mouse drag action. 但这只是阻止任何鼠标拖动动作。 It also prevents text selection. 它还可以防止文本选择。 How can we enable all content editing mouse actions for the child content editable while keeping the draggable on the parent? 我们如何为子内容编辑所有内容编辑鼠标操作,同时保持父项的可拖动性?

Try something like this: 尝试这样的事情:

var draggableDiv = $('#draggable').draggable();

$('#editable', draggableDiv).mousedown(function(ev) {
     draggableDiv.draggable('disable');
}).mouseup(function(ev) {
     draggableDiv.draggable('enable');
});

Fiddle 小提琴

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

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