<!DOCTYPE html> <html> <body> <h1>Element 对象</h1> <h2>focus() 和 blur() 方法</h2> <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>