Home > Web Front-end > JS Tutorial > Usage of textarea focus to achieve focus clearing and loss of focus prompt effect_javascript skills

Usage of textarea focus to achieve focus clearing and loss of focus prompt effect_javascript skills

PHP中文网
Release: 2017-03-28 16:13:36
Original
2569 people have browsed it

Rendering:
Usage of textarea focus to achieve focus clearing and loss of focus prompt effect_javascript skills
Specific implementation:

1. Textarea tag content

Copy code The code is as follows:







2. Initialization allows you to enter up to 50 characters when you click the add button.

Copy code The code is as follows:


$("#introduction").val("Can enter up to 50 characters");
document.getElementById("introduction").style.color="gray";


3. js script

Copy code The code is as follows:


function getAddFocus(id){//For the add operation Introduction and remarks in, textarea gets focus and clears the input box
var textarea=document.getElementById(id);
textarea.value="";
textarea.style.color="black";
}

function lostAddFocus(id){//For the introduction and remarks in the add operation, when the textarea loses focus and the content is empty, a prompt message is displayed
var textarea=document.getElementById(id);
var textarea_value=textarea.value;
if(textarea_value==""){
textarea.value="Can enter up to 50 characters";
textarea.style.color="gray" ;
}
}


Usage reference of textarea focus written by csdn partner:

Copy code The code is as follows:


1. The text box displays the default text:



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





 5. Move the mouse to the text box, the default text disappears, move the mouse out of the text box, and the default text reappears:



 6. Click the mouse on the text box, and any text in the text box will disappear (including the default text and Text entered later):



 7. Move the mouse to the text box, and any text in the text box will disappear (including the default text and later entered text):



 8. Click the text box and select all text boxes Text inside:



 10. After pressing Enter, the focus shifts from the current text box to the next A text box:



 11. After pressing Enter, the focus shifts from the current text box to the specified position:

< ;textarea onkeypress="return focusNext(this,'id name of the specified location',event)">White Pigeon Boy

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template