![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
30/04/2007, 09:30
|
| | Fecha de Ingreso: abril-2006
Mensajes: 80
Antigüedad: 18 años, 10 meses Puntos: 2 | |
Re: Insertar foco entre dos elementos Prueba algo así:
Código:
var txarea, abierto, cerrado;
// Aquí le das el valor a txarea, abierto y cerrado
txarea.focus();
var navegador= navigator.appName;
if (navegador=='Microsoft Internet Explorer')
{
seleccion= document.selection.createRange();
seleccion.text= abierto+seleccion.text+cerrado;
}
else // Otro navegador
{
var textoEntero= txarea.value;
var pos1= txarea.selectionStart;
var pos2= txarea.selectionEnd;
var pos3= textoEntero.length;
var textoAnterior= textoEntero.substring(0,pos1)+abierto;
var textoSeleccionado= textoEntero.substring(pos1,pos2);
var textoPosterior= cerrado+textoEntero.substring(pos2,pos3);
txarea.value= textoAnterior+textoSeleccionado+textoPosterior;
txarea.selectionStart= pos1+abierto.length;
txarea.selectionEnd= pos2+abierto.length;
}
|