1. Control the number of characters entered by the user
For single-line text boxes and password entry boxes, you can use the MaxLength property to control the number of characters entered by the user.
For multiline text, MaxLength is a custom attribute with a value of up to the number of characters entered, and the onkeypress event occurs when the return value of the LessThan () function is returned, the function is as follows
<name= "comments" ID= "comments" cols= "Max" rows = "4" maxlength = " the" = "return LessThan (this);" ></ textarea >
Detailed code
<script language= "JavaScript" >function LessThan (Otextarea) {//returns whether the number of characters in the text box is the Boolean value required for the symbol return OTextArea.value.length < Otextarea.getattribute ("MaxLength");} </script><form method= "POST" name= "MyForm1" action= "addinfo.aspx" ><p><label for= "name" > Please enter your name: </label><input type= "text" name= "name" id= "name" class= "TXT" value= "name" Maxlength= "Ten" ></p ><p><label for= "Comments" > I want to leave a message: </label><br><textarea name= "Comments" id= "comments" Cols= "rows=" 4 "maxlength=" onkeypress= "return LessThan (this); ></textarea></p><p><input type= "Submit" Name= "Btnsubmit" id= "btnsubmit" value= "Submit" class= "BTN" ><input type= "reset" name= "btnreset" id= "btnreset" value= "reset" class= "BTN" ></p></ Form>
2. Set the mouse to automatically select text
The first is the auto focus when the mouse is over onmouseover = "This.focus"
Next is onfocus = "this.select ()"
code example:
<formMethod= "POST"name= "Form1"ID= "Form1"Action= "Addinfo.aspx"><inputtype= "text"name= "Name"ID= "Name"class= "txt"value= "Name"onmouseover= "This.focus ()"onfocus= "This.select ()"></form>
For multiple code instances, you can use the following code to focus
<Scripttype= "Text/javascript"> functionMyfocus () { This. focus (); } functionMyselect () { This. Select (); } window.onload= function() { varOform=document.forms["MyForm1"]; OForm.name.onmouseover=Myfocus; OForm.name.onfocus=Myselect; } </Script> <formMethod= "POST"name= "MyForm1"Action= "Addinfo.aspx"> <P> <label for= "Name">Please enter your name:</label> <inputtype= "text"name= "Name"ID= "Name"class= "txt"value= "Name"> </P> <P> <label for= "passwd">Please enter your password:</label> <inputtype= "Password"name= "passwd"ID= "passwd"class= "txt"> </P> <P> <inputtype= "Submit"name= "Btnsubmit"ID= "Btnsubmit"value= "Submit"class= "BTN"> <inputtype= "Reset"name= "Btnreset"ID= "Btnreset"value= "Reset"class= "BTN"> </P> </form>
Dom (ix) Setting a text box with the DOM