Requirements: Click button to get the selected content in the input box, so that the selected content turns red.
Implementation: The code is as follows
<!DOCTYPE HTML><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><title>Test</title><style type="text/css">div{display: none;}</style></head><body><input type="text" id="txt" value="" /> <input type="button" value="get the value in the text box" id="btn" onclick="getText();"/><div id="showText"></div><script type="text/javascript">function getText () {var showText = document.getElementById("showText");showText.style.display = "block";showText.style.color = "red";showText.innerHTML=document.getElementById("txt").value;}</script></body></html>Effect: