慕侠9801077
2017-05-30 15:56
请问如何实现把选中的文字alert出来?比如我有一篇英语文章,怎么才能我选中一个单词就会alert一个单词?
alert语句结束不是还要加上分号吗
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> 内容选中事件 </title>
<script type="text/javascript">
function message(event){
alert(window.getSelection()) }
</script>
</head>
<body>
<form>
个人简介:<br>
<textarea name="summary" cols="60" rows="5" onselect="message(event)">请写入个人简介,不少于200字!</textarea>
</form>
</body>
</html>我这样是ok的
我好像之前回答过这个问题,应该用的是 window.getSelection()方法,这个方法会返回你选中的单词,
function message(event){
alert(window.getSelection()) }JavaScript进阶篇
469072 学习 · 22582 问题
相似问题