开发者

jQuery function (append some text to textarea)

I'm trying to make a working JS function which ought to add some text from argument to textarea, without erasing it's content.

<textarea id="message" name="message" cols="48" rows="4" accesskey="m"></textarea>

So the code above is a code of my textarea. And the script below should add some text to its value but it doesn't work.

function appendpostid( postid ) {
    $('#message').val($('#message').val() + postid);
}

And, if it's important, here is the code that calls that function:

<a href="javascript:void(0)" onclick="appendpostid('."'>>".$rpl["id"]."'".')">'.$rpl["id"].'</a>

Code from generated page:

<a href="javascript:void(0)" onclick="appendpostid('>>69')">69</a>
开发者_运维技巧

What am I doing wrong? Thanks in advance!


Your code works: http://jsfiddle.net/d4pKt.
Also make sure that the function is not inside the jquery .ready or it doesn't work


I'm not sure a textarea has a value attached to it that you can manipulate. Please try:

function appendpostid( postid ) {
     $('#message').append(postid);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜