Requisitos: haga clic en el botón para obtener el contenido seleccionado en el cuadro de entrada, de modo que el contenido seleccionado se ponga rojo.
Implementación: el código es el siguiente
<! DocType html> <html> <fead> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"> <title> test </title> <style type = "text/css"> div {visual type = "Button" Value = "Obtener el valor en el cuadro de texto" id = "btn" onClick = "getText ();"/> <div id = "showText"> </div> <script type = "text/javascript"> function getText () {var showText = document.getElementById ("showText"); showText.style.dyle.dyleDDExplay = "" Bloquet ". = "rojo"; showText.innerhtml = document.getElementById ("txt"). valor;} </script> </body> </html>Efecto: