요구 사항 : 버튼을 클릭하여 선택한 컨텐츠를 입력 상자에서 가져 오면 선택한 컨텐츠가 빨간색으로 변합니다.
구현 : 코드는 다음과 같습니다
<! docType html> <html> <head> <meta http-equiv = "content-type"content = "text/html; charset = utf-8"> <title> test </title> <style type = "text/css"> css "> div {display : none;} </style> <body> <input ="id = "txt" <입력 유형 = "버튼"value = "텍스트 상자"id = "id ="btn "onclick ="getText (); "/> <div id ="showtext "> </div> <script type ="text/javaScript "> function getText () {var showtext = document.getElementById ("showText "); showText.Stele.displypherpherpypherpherpherpherpherpherpy. "block"; showtext.style.color = "red"; showtext.innerhtml = document.getElementByid ( "txt"). value;} </script> </body> </html>효과: