The cursor is located in the corresponding table item when the table item content is empty:
In the case of form validation, generally, if a form item does not pass validation, then this form item will get the focus, the position of the cursor will be in this form project, the following is a brief introduction to how to achieve the sub-effect.
The code example is as follows:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><Scripttype= "Text/javascript">functionChkform () {if(document.getElementById ("username"). Value=="") {alert ("the user name cannot be empty! "); document.getElementById ("username"). focus (); return false; } if(document.getElementById ("PW"). Value=="") {alert ("The password cannot be empty! "); document.getElementById ("PW"). focus (); return false; }}</Script></Head><Body><formAction= "Http://www.softwhy.com"name= "MyForm"> <Table> <TR> <TD>User name:</TD> <TD><inputtype= "text"name= "username"ID= "username" /></TD> </TR> <TR> <TD>Password:</TD> <TD><inputtype= "Password"name= "PW"ID= "PW" /></TD> </TR> <TR> <TDcolspan= "2"><inputtype= "Submit"value= "Submit"></TD> </TR> </Table></form></Body></HTML>
In the above code, if the user name or password does not pass the validation, then the corresponding table item will get the focus, that is, the cursor inside. The way to do this is to call the object's focus () function so that the current object gets focus.
The original address is: http://www.51texiao.cn/javascriptjiaocheng/2015/0428/304.html
The most original address is: http://www.softwhy.com
The cursor is in the corresponding table item when the table item content is empty