废话不说,直接上代码:
<!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>
页面中的文字,通过选中后自动弹出选择的文字!