Ver Mensaje Individual
  #17 (permalink)  
Antiguo 12/12/2012, 17:48
edward18_1
 
Fecha de Ingreso: septiembre-2011
Mensajes: 480
Antigüedad: 12 años, 8 meses
Puntos: 18
Respuesta: Colocar Foco en una parte del texto en especifico

compañero la funcion me va quedando asi,

Código Javascript:
Ver original
  1. function ponCursorEnPos(pos){  
  2. laCaja = document.getElementById('#' + marcado)
  3.  
  4.     if(typeof document.selection != 'undefined' && document.selection){        //método IE
  5.         var tex=laCaja.value;
  6.         laCaja.value='';  
  7.         laCaja.focus();
  8.         var str = document.selection.createRange();  
  9.         laCaja.value=tex;
  10.         str.move("character", pos);  
  11.         str.moveEnd("character", 0);  
  12.         str.select();
  13.     }
  14.     else if(typeof laCaja.selectionStart != 'undefined'){                    //método estándar
  15.         laCaja.setSelectionRange(pos,pos);  
  16.         forzar_focus();            //debería ser focus(), pero nos salta el evento y no queremos
  17.  
  18. }
  19.  
  20. }

la ejecuto con esto

Código Javascript:
Ver original
  1. $('#'+marcado).focus();
  2.     ponCursorEnPos(5);

y me da el siguiente error en el chorme

Uncaught TypeError: Cannot read property 'selectionStart' of null