编辑下面的代码:【加编码】
<html> <body> <input type="text" id="myText" value="文本域"> <p>点击按钮让文本域获取或者失去焦点。</p> <button type="button" onclick="getFocus()">获取焦点</button> <button type="button" onclick="loseFocus()">失去焦点</button> <script> function getFocus() { document.getElementById("myText").focus(); } function loseFocus() { document.getElementById("myText").blur(); } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂