空话不说,直接上代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
document.onmouseup = document.ondbclick= selceText;
function selceText(){
var txt;
if(document.selection){
txt = document.selection.createRange().text
}else{
txt = window.getSelection()+'';
}
if(txt){
alert(txt);
}
}
</script>
</head>
<body>
<p>哈哈哈呵呵呵呵嘿嘿</p>
</body>
</html>
页面中的笔墨,经由过程选中后自动弹出挑选的笔墨!