Pre written text into textarea
I want to make text area, where always is pre written text, and that piece of text is located at the end, and it wouldn't be possible to delete. For example, you write answer here,开发者_开发知识库 and at the end, right side of cursor, is text "This is end of my answer".
And when you POST it, it displays your written text and "This is end of my answer" at the end.
I know, that I can attach this text easily after posting it, but it must be displayed, and anyone could see it.
I need javascript/jQuery solution.
Thanks!
The text to the right side of the cursor, that moves as you type is really annoying and zero-usable. However, if you want something like that I would suggest putting a background image on the textarea with the text you want. It will be static and none will be able to edit it, and at the same time will always see it.
<input class="myinput" name="myinput" type="text" value="Text_Ends_Here" /></input>
$("input[name=myinput]").click(function()
{
var currentValue = $(this).val();
currentValue = currentValue.replace("Text_Ends_Here", "");
$(this).val(currentValue);
}
);
$("input[name=myinput]").focusout(function()
{
var currentValue = $(this).val();
$(this).val(currentValue + ' Text_Ends_Here');
}
);
http://jsfiddle.net/gXvLB/95/
You can position the required text over textarea using positioning.
精彩评论