javascript对象之 selectionStart selectionEnd
2014-04-15 11:23
483 查看
<script> function inserttag(){ var text=document.getElementById('con'); text.focus(); var start=text.selectionStart; var end = text.selectionEnd; var ss = text.value.substring(start, end); alert(ss); //alert(start); } </script> <form action="" method="post"> <textarea name="text" id="con" cols="30" rows="10">The text selection appears here</textarea> <input type="submit" onclick="inserttag()" name="sub" value="OK"> </form>
用鼠标选取一块 效果图:
<html> <head> <title>Selection Start and End example</title> <script type="text/javascript"> function SelectSomeText () { var input = document.getElementById ("Textbox"); input.selectionStart = 4; input.selectionEnd = 13; } </script> </head> <body> <p><input type="text" id="Textbox" size="40" value="The text selection appears here"/></p> <p><button onclick="SelectSomeText ()">See selection</button></p> </body> </html>
效果图:
相关文章推荐
- 实现一个打点计时器,要求 1、从 start 到 end(包含 start 和 end),每隔 100 毫秒 console.log 一个数字,每次数字增幅为 1 2、返回的对象中需要包含一个 can
- javascript moveStart和moveEnd方法(TextRange对象--查找与选择)
- [Javascript] String Padding in Javascript using padStart and padEnd functions
- javascript中的数组(Array)对象的使用
- JavaScript中创建RegExp对象的两种方式
- javascript中对象的深拷贝
- javascript的Document对象——事件
- javascript document对象的属性和方法
- JavaScript:类似数组的对象
- JavaScript 对象与数组参考大全
- javascript语言扩展:可迭代对象(1)
- java 正则表达式group,start,end的用法
- 深入理解JavaScript系列(12):变量对象(Variable Object)
- MANUAL and AUTOMATIC start/end modes
- C++可变参数编程,va_start va_arg va_end 的使用和原理
- javascript语言扩展:可迭代对象(4)
- JavaScript 使用简略语法创建对象的代码
- javascript实践-Jquery之Jquery对象与DOM对象
- javascript中cookie对象用法实例分析
- javascript中神奇的 Date对象小结