1,DOM节点
<div @mouseup='updateXY'">
</div>
2,鼠标事件
updateXY:function(event){
var button = event.button;
// 鼠标左击
if(button == 0){
this.getSelectedContents();
}
},
3,获取鼠标选中的数据
getSelectedContents:function() {
if (window.getSelection) { //chrome,firefox,opera
var range = window.getSelection().getRangeAt(0);
var container = document.createElement('div');
container.appendChild(range.cloneContents());
// 不带有dom的文字
// console.log(range);
// 带有dom的文字
// console.log(container.innerHTML);
this.getSessionTextOld = range.toString();
}
else if (document.getSelection) { //其他
var range = window.getSelection().getRangeAt(0);
var container = document.createElement('div');
container.appendChild(range.cloneContents());
this.getSessionTextOld = range.toString();
}
else if (document.selection) { //IE特有的
this.getSessionTextOld = document.selection.createRange().htmlText;
}
}