3
我在我的一個應用程序中構建了一個簡單的blogging-esque功能,並使用HTML5 contenteditable屬性,因爲它很乾淨。不過,我現在需要做的是當用戶突出顯示contenteditable div中的某些文本時,彈出窗口需要出現在其上方。現在我有一個函數獲取選定的文本,它綁定到DIV的mouseup()。但是,當我點擊進入contenteditable 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?");
};
});
我該如何防止被解僱的電話,當用戶點擊進入CONTENTEDITABLE DIV,只有當他們突出一些文字?
那麼你的代碼做錯了什麼? – ccleve