开发者

Append text into TextArea

开发者 https://www.devze.com 2023-03-13 20:43 出处:网络
I want to append text inside Textarea. The text should be appended immediate after the cursor position and not at the end.

I want to append text inside Textarea. The text should be appended immediate after the cursor position and not at the end.

Here is my code:

The HTML:

<html>
<开发者_高级运维;head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<textarea id="textarea1"></textarea>
<br><input type="button" value="Write blah blah" onclick="addtxt('textarea1')">
</body>
</html>

The Script:

<script>
function addtxt(input) {
var obj=document.getElementById(input);
obj.value+="blah test 123"
}
</script>

The above code is live at: http://jsfiddle.net/zGrkF/

Thanks in advance..


Try jQuery.

With that the code is the following:

$("#textarea1").hover(
    function()
    {
        $(this).value('IN');
    },
    function()
    {
        $(this).value('OUT');
    });

OR

$("#textarea1").mouseover(
    function()
    {
        $(this).value('IN');
    });

UPDATED:

Try this link


The jQuery Field Selection plugin is quite old but should enable you to do everything you want and more.

0

精彩评论

暂无评论...
验证码 换一张
取 消