html中的css和js控制input,textarea文字框自動獲取焦點
阿新 • • 發佈:2019-02-14
方法:1:js控制自動獲取焦點
<html> <head> <script type="text/javascript"> function setFocus() { document.getElementById('password1').focus() } function loseFocus() { document.getElementById('password1').blur() } </script方法2:css控制> </head> <body> <form> <input type="password" id="password1" value="thgrt456" /> <input type="button" onclick="setFocus()" value="Set focus" /> <input type="button" onclick="loseFocus()" value="Lose focus" /> </form> </body> </html>
<input type="tel" autofocus="autofocus"> <!--這一行程式碼其實就夠了!-->