Home >Web Front-end >JS Tutorial >DOM basic tutorial: Using DOM to set text boxes_Basic knowledge

DOM basic tutorial: Using DOM to set text boxes_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:18:431063browse

1. Control the number of characters entered by the user

For single-line text boxes and password input boxes, you can use the maxlength attribute to control the number of characters entered by the user.
For multi-line text, maxlength is a custom attribute whose value is the maximum number of characters entered. When the onkeypress event occurs, the return value of the LessThan() function is returned. The function is as follows


Detailed code

Copy code The code is as follows:











2. Set the mouse to automatically select text

The first is to automatically focus when the mouse passes over onmouseover = "this.focus"

The second is onfocus = "this.select()"
Code example:

Copy code The code is as follows:




For multiple code instances, you can use the following code to focus

Copy code The code is as follows:


           

               


                   
                   
               


               


                   
                   
               


               


                   
                   
               


           

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn