Anforderungen: Klicken Sie auf die Schaltfläche, um den ausgewählten Inhalt im Eingabefeld zu erhalten, damit der ausgewählte Inhalt rot wird.
Implementierung: Der Code ist wie folgt
<! DocType html> <html> <kopf> <meta http-äquiv = "content-type" content = "text/html; charset = utf-8"> <title> test </title> <style type = "text/css"> div {tit} id: keine; type = "button" value = "den Wert im Textfeld" id = "btn" onclick = "getText ();"/> <div id = "showText"> </div> <script type = "text/javaScript"> Funktion getText () {var showText = document.getElementById ("showtext");); "block"; showText.style.color = "red"; showText.innerhtml = document.getElementById ("txt"). Wert;} </script> </body> </html>Wirkung: