第一种:使用JavaScript实现
E:\GitHub\tools\JavaEEDevelop\Lesson4_JavaScript_Demo1\day02\part01\focus1.html
1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <table> 9 <tr> 10 <td>图书</td> 11 <td> 12 <input type="text" name="book" id="book" /> 13 </td> 14 </tr> 15 <tr> 16 <td>价格</td> 17 <td> 18 <input type="text" name="price" id="price" /> 19 </td> 20 </tr> 21 </table> 22 <script type="text/javascript"> 23 document.getElementById("book").focus(); 24 </script> 25 </body> 26 </html>
第二种:使用HTML5属性实现
E:\GitHub\tools\JavaEEDevelop\Lesson4_JavaScript_Demo1\day02\part01\focus2.html
1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <table> 9 <tr> 10 <td>图书</td> 11 <td> 12 <input type="text" name="book" id="book" /> 13 </td> 14 </tr> 15 <tr> 16 <td>价格</td> 17 <td> 18 <input type="text" name="price" id="price" autofocus/> 19 </td> 20 </tr> 21 </table> 22 </body> 23 </html>
时间: 2024-10-05 04:40:42