js & right click menu & 鼠标滑词

js & right click menu & 鼠标滑词


// 鼠标滑词
mouseSlipGetWords() {
const getSelectionText = () => {
let selectedTextWithTrim = ``;
if (window.getSelection){
// all modern browsers and IE9+
selectedTextWithTrim = window.getSelection().toString().trim();
// console.log(`you selected text with trim() =`, selectedTextWithTrim);
} else {
console.error(`鼠标滑词 selectedText is empty!`);
}
return selectedTextWithTrim;
};
let textarea = document.querySelector(`#audit-common-handle-text`);
let that = this;
if (document.addEventListener) {
// IE >= 9; other browsers
textarea.addEventListener('contextmenu', function(e) {
let value = getSelectionText() || "";
if (value) {
that.$hMessage.success(`滑动选取的单词: ${value}`);
// that.isNewAddLabel = true;
// that.tableLoading = true;
that.commonHandleModalTableData = [];
that.searchValue = value;
// update value with auto click
that.getLabelCategories(``, ``);
that.onClickSearch();
setTimeout(() => {
// show modal with delay
that.modalNew.showModal = true;
}, 0);
} else {
console.log(`selected text is empty!`);
that.$hMessage.error(`滑动选取的单词不可为空`);
// this.$hMessage.info(`滑动选取的单词不可为空`);
}
e.preventDefault();
}, false);
} else {
// IE < 9
document.attachEvent('oncontextmenu', function() {
// alert("You've tried to open context menu");
window.event.returnValue = false;
});
}
},

&copyxgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


上一篇:angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)


下一篇:spring @Qualifier注解使用