textarea文本选择onselect事件初探
2012-02-29 22:06
302 查看
<html> <head> <style type='text/css'> textarea{ border:solid 1px green; width:200px; height:200px; } </style> <script language='javascript'> var sel_obj; function fun(obj) { //alert(obj.selected) sel_obj=document.selection.createRange(); if(!sel_obj.text){ alert('没有选择到文本!'); }else{ //alert(sel_obj.text); document.title=sel_obj.text; } } </script> </head> <body> <textarea onselect='fun(this);'>hello world hello world</textarea> </body> </html>
这里每选中一次文本,都要使用document.selection.createRange重新建立对象,以便使用text属性,获取选中的内容。
这个onselect事件,在div中并不存在。
相关文章推荐
- Socket I/O模型之事件选择(WSAEventSelect)(转)
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参
- js事件驱动机制单oncontextmenu,onselectstart事件
- js触发select onchange事件的小技巧
- js触发select onchange事件的小技巧
- jQuery取得select选择的文本与值
- onselectstart与onselect—禁止选择或禁止复制
- WSAEventSelect(事件选择)模型
- 根据角色的选择获取对应信息 选择器事件 on()
- jQuery取得select选择的文本与值
- jQuery取得select选择的文本与值
- jQuery取得select选择的文本与值
- JS实现选择TextArea内文本的方法
- 移动端使用zepto选择Select标签文本出错解决方案
- jQuery获取select选择的文本和值(转)
- html5 表单 填表 select 下拉 textarea多行文本 output Js计算结果
- asp.net中,js改变textBox的文本内容的触发事件是onpropertychange
- 通过selectstart事件可以直接获得文本节点
- -moz-user-select与onselectstart 禁止选择文字
- jQuery取得select选择的文本与值