要件:[ボタン]をクリックして、選択したコンテンツを入力ボックスで取得し、選択したコンテンツが赤くなるようにします。
実装:コードは次のとおりです
<!doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"> <title> <title> <style> <style> <style type = "text/css"> div {disply:none;} </style> <input> <input> < type = "button" value = "テキストボックスで値を取得" 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>効果: