I have a textarea which when in focus should empty the text holder and when out of focus should get back the original text or retain any text that was wr开发者_运维知识库itten while in focus.
EDIT:
i know how to select the text area. $("textarea").text();
i am not sure how to clear the content when u click on the textarea to nothing and then again get back the content when out of focus.
Just add the placeholder
parameter:
<input type="text" name="name" placeholder="input placeholder" />
<textarea name="comment" placeholder="textarea placeholder"></textarea>
It seems you're trying to do the thing where you get instructions in the textarea and then if you delete the value you get the instructions again. Try this
<textarea id="a">Message</textarea>
var standard_message = $('#a').val();
$('#a').focus(
function() {
if ($(this).val() == standard_message)
$(this).val("");
}
);
$('#a').blur(
function() {
if ($(this).val() == "")
$(this).val(standard_message);
}
);
You can see it working here.
精彩评论