日期:2014-05-16  浏览次数:20403 次

我想找出文本框里哪些被选中了,哪些在选中的前面,哪些在选中块的后面,怎么弄?
比如 "aaaaaaaaaabbbbbbbbbbcccccccccc "是一个文本框的内容
其中bbbbbbbbbbb被选中
我要单独找出aaaaaaaaaaaa,bbbbbbbbbbbb,ccccccccc
谢谢


------解决方案--------------------
Details see TextRange Object
------解决方案--------------------
樓主,給個例子你,你自己做拆分字符串吧

<input type=text id=txt1> <input type=button value= "go " onclick= "go(); ">

<script>
function go(){
//得到文本框的值
var t = document.getElementById( "txt1 ").value;
//得到選中的值
var r = document.selection.createRange().text;
//拆分
...
}
</script>
------解决方案--------------------
<html>
<body>
<input type=text id= "box " value= "我是谁? ">
<input type=button onclick= "tt() " name= 'test2 ' value = 'tttt ' ID= "Button2 ">
<script language= "javascript ">
function tt()
{
range = document.selection.createRange()
if(range.text!= " ")
range.text= '塞北的雪 ';
}
</script>
</body>
</html>

------解决方案--------------------
<SCRIPT>
function aa()
{
var selRg = document.selection.createRange()
var str = selRg.text
var totalRg = document.all.oTxt.createTextRange()
if(totalRg.inRange(selRg))
{
do
{
var selText = selRg.text
selRg.expand( "character ")
}
while(selRg.text.substring(selText.length, selRg.text.length) != " ")

var afterStr = selRg.text.substring(str.length, selRg.text.length)
var beforeStr = totalRg.text.substring(0, totalRg.text.length - selRg.text.length)
alert( "前: " + beforeStr + "\n中: " + str + "\n后: " + afterStr)
}
}
</SCRIPT>

<BUTTON onclick= "aa() "> Click here </BUTTON>
abc
<input ID=oTxt value= "aaaaaabbbbbccccc ">