window.onload=function(){ document.getElementById('txt').onMouseUp=function(){ var text=window.getSelection(); if(text.toString().length>1){ alert(text);} }}//txt是页面文字所在div的id,应用的chrome浏览器,暂时不考虑其他浏览器兼容问题。
2 回答
已采纳
慕标2337738
TA贡献23条经验 获得超13个赞
<!DOCTYPE html> <html> <head> <title>2.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <script type="text/javascript"> window.onload=function(){ document.getElementById('txt').onmouseup=function(){ var text=window.getSelection(); if(text.toString().length>1){ alert(text);} } } </script> <body id="txt"> This is my HTML page. <br> </body> </html> --mouseup首字母大写了
添加回答
举报
0/150
提交
取消