Ver Mensaje Individual
  #4 (permalink)  
Antiguo 20/10/2005, 10:27
Avatar de Vaalegk
Vaalegk
 
Fecha de Ingreso: abril-2005
Mensajes: 154
Antigüedad: 19 años, 1 mes
Puntos: 2
asi?:
Código HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script language="javascript">
function ReplaceEnters(texto, conbr) {
 //para que funcione en IE y Firefox
 var nl=document.all?String.fromCharCode(13):"\n";
 if (conbr) { 	
 	while(texto.indexOf(nl)>=0){
	  texto = texto.replace(nl, "<br/>");
	  /*en IE aunque remplaces los char(13) los saltos se mantienen, debes hacer esto*/
	  if(document.all)  texto = texto.replace("\n", "");
	}
 } else {
	while(texto.indexOf("<br/>")>=0){
	  texto = texto.replace("<br/>",nl);
	}
 }
 return texto;
}
</script>
<body>
<textarea name="test" id="test" rows="10" cols="50"></textarea>
<input type="button" value="code" onclick="document.getElementById('test').value=ReplaceEnters(document.getElementById('test').value, true)"/>
<input type="button" value="decode" onclick="document.getElementById('test').value=ReplaceEnters(document.getElementById('test').value, false)"/>

</body>
</html>