Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/10/2005, 11:44
Avatar de tunait
tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Buenas a todos

Saruman, se puede simplificar usando el String.fromCharCode(13) como expresión regular de la siguiente forma
Código:
<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) {
 if (conbr) {
 pat = new RegExp(String.fromCharCode(13),"g")
  texto = texto.replace(pat, "<br>");
 } else {
  texto = texto.replace(/<br>/g, String.fromCharCode(13));
 }
 alert(texto);
}
</script>
<body>
<textarea name="test" id="test" rows="10" cols="50"></textarea>
<input type="button" value="ok" onclick="ReplaceEnters(document.getElementById('test').value, true)"/>
</body>
</html>
Saludos