您的位置:首页 > Web前端 > JavaScript

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>


效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: