<!DOCTYPE html> <html> <body> <h1>Element 对象</h1> <h2>setAttribute() 方法</h2> <input id="myInput" value="OK"> <p>单击“更改”将输入字段更改为输入按钮。</p> <button onclick="myFunction()">更改</button> <script> function myFunction() { document.getElementById("myInput").setAttribute("type", "button"); } </script> </body> </html>