所以我在我的Rails应用程序中有一个可以理解的div,当它突出显示时,需要能够在文本上方显示一个小的弹出窗口。目前我的代码有效,并在警报中显示突出显示的文本。但是,该函数在mouseup上执行,因此当您单击div以开始键入或突出显示时,会引发空警报。在ContentEditable DIV中获取所选文本?
这里是我的代码:
function getSelected() {
if (window.getSelection) {
return window.getSelection();
}
else if (document.getSelection) {
return document.getSelection();
}
else {
var selection = document.selection && document.selection.createRange();
if (selection.text) {
return selection.text;
}
return false;
}
return false;
};
$("#content-create-partial").bind("mouseup", function(){
var text = getSelected();
if(text) {
console.log(text);
}
else{
console.log("Nothing selected?");
};
});
如何以免jQuery当用户点击执行功能到CONTENTEDITABLE DIV?我只希望它在实际文本突出显示时执行。