私は自分のアプリの 1 つに単純なブログ風の機能を構築しており、HTML5 の contenteditable 属性を使用しています。ただし、ユーザーが contenteditable div 内のテキストを強調表示したときに、その上にポップアップを表示する必要があります。現在、選択したテキストを取得する関数があり、これは DIV の mouseup() にバインドされています。ただし、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?");
};
});
ユーザーが contenteditable div をクリックしたときに、テキストを強調表示したときにのみ呼び出しが発生しないようにするにはどうすればよいですか?