Js implementation form (textarea) Acquisition and focus usage

Source: Internet
Author: User

Js implementation form (textarea) Acquisition and focus usage

In js, onfocus, onblur, onmouseover, and so on will be used. jquery binds events. The following uses textarea as an example. If input is used, the value is written differently.

1. display the default text in the text box:

The Code is as follows:  

<Textarea> front-end development-csswang </textarea>

2. Click the text box, and the default text disappears:

The Code is as follows:  

<Textarea onfocus = "if (value = 'frontend development-csswang') {value =''} "> frontend development-csswang </textarea>

3. move the cursor to the text box, and the default text disappears:

The Code is as follows:  


<Textarea onmouseover = "focus ()" onfocus = "if (value = 'frontend development-csswang') {value =''} "> front-end development-csswang </textarea>

4. Click the text box, and the default text disappears. Click any area outside the text box to reproduce the default text:

The Code is as follows:  


<Textarea onfocus = "if (value = 'frontend development-csswang') {value =''} "onblur =" if (value = '') {value = 'frontend development-csswang'} "> frontend development-csswang </textarea>

5. Move the mouse to the text box. The default text disappears. Move the mouse out of the text box. The default text is displayed again:

The Code is as follows:  

<Textarea onmouseover = "focus ()" onfocus = "if (value = 'frontend development-csswang') {value =''} "onmouseout =" blur () "onblur =" if (value = '') {value = 'frontend development-csswang'}"> frontend development-csswang </textarea>

6. Click the text box, and any text in the text box will disappear (including the default text and subsequent text ):

The Code is as follows:  

<Textarea onclick = "value ='' "> front-end development-csswang </textarea>

7. move the cursor to the text box, and any text in the text box disappears (including the default text and subsequent text ):

The Code is as follows:  

<Textarea onmouseover = "value ='' "> frontend development-csswang </textarea>

8. Click the text box and select all text in the text box:

The Code is as follows:  

<Textarea onfocus = "select ()"> frontend development-csswang </textarea>

9. move the cursor to the text box and select all text in the text box:

The Code is as follows:  

<Textarea onmouseover = "focus ()" onfocus = "select ()"> front-end development-csswang </textarea>

10. Press enter and move it from the current text box to the next text box:

The Code is as follows:  

<Textarea onkeydown = "if (event. keyCode = 13) event. keyCode = 9"> front-end development-csswang </textarea>

11. Press enter and move the focus from the current text box to the specified position:

The Code is as follows:  

Textarea onkeypress = "return focusNext (this, 'Id of the specified location', event)"> front-end development-csswang </textarea>

At last, although I sorted this place out, the default text disappears when I move the mouse to the text box and move the mouse out of the text box. The default text is displayed again. I strongly recommend that you do not use Method 5. Use the jquery method.

The Code is as follows:  

(Function () {$ ("# q"). focus (function () {(this. value = 'Enter the project name ')? This. value = '': false}); $ (" # q "). blur (function () {(this. value = '')? This. value = 'Enter the project name ': false });}());

Instead of writing it in a form, you can directly bind the form input id with jquery and then perform operations. This is good for the concise page and seo optimization.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.