<textarea rows="7" cols="49" id="box" onclick=tellPoint()>
asdfasdfasdfasdfasdfasdfasdfasdfsadfsdffasdfasdfasdfasdfasdfasdfdfeeertryfgdfgdsasdfieukmkljxuekjalkjdfkljeuelkjdlkfjleu
</textarea>
 
<script> 
 
function movePoint() 

 var p1 = parseInt(prows.value); 
 var p2 = parseInt(pcols.value);
 var pn=parseInt((p1-1)*(box.cols)+p2);
  
 if(isNaN(pn)) 
  return; 
  
 var rng = box.createTextRange(); 
   
 rng.moveStart("character",pn); 
  
 rng.collapse(true);  
  
 rng.select(); 

</script>
<input type="text" value="0" id="prows" size="8">
<input type="text" value="0" id="pcols" size="8">
<input type="button" onclick="movePoint()" value="移动光标到指定位置">

解决方案 »

  1.   

    谢谢石井坚!
    不过还有问题,如果textarea是这样的:
    <textarea rows="7" cols="49" id="box" onclick=tellPoint()>
    谢谢谢谢谢大家!
    ertryfgdfgdsasdfieukmkljxuekjalkjdfkljeuelkjdlkfjleu
    </textarea>
    就没办法定位到指定位置,比如说行首
    不知道还有没有对付空字符的办法
      

  2.   

    <form name=aa>
    <input type=text><br>
    <input type=text><br>
    <input type=text><br>
    <input type=text><br>
    <input type=text><br>
    <input type=text><br>
    <input type=text><br>
    <input type=text><br>
    <input type=text><br>
    </form>
    ------------------------------------------------------------------------------
    请输入要跳转到的行数:<input type=text id=bb ><button onclick=cc(document.aa)>跳转</button>
    <script>
    function cc(obj){
    var No = document.all.bb.value;
    No = parseInt(No) -1 ;
    obj.elements[No].focus()}
    </script>
      

  3.   

    sorry,the question ia about
    textarea,not text
      

  4.   

    主要是硬回车定位,还有就是汉字(本来指定cols=30,定位第一行的20时候,如果是英文,正确,如果是汉字,就会定位到第2行去了)
      对不起,我没有好办法,等待高手吧