Add text to textarea - Jquery

2019-01-18 01:32发布

How can I add text from a DIV to a textarea?

I have this now:

    $('.oquote').click(function() { 
      $('#replyBox').slideDown('slow', function() {
      var quote = $('.container').text();   
         $('#replyBox').val($('#replyBox').val()+quote);   
        // Animation complete.
      });    
    });

2条回答
SAY GOODBYE
2楼-- · 2019-01-18 01:45

That should work. Better if you pass a function to val:

$('#replyBox').val(function(i, text) {
    return text + quote;
});

This way you avoid searching the element and calling val twice.

查看更多
beautiful°
3楼-- · 2019-01-18 02:09

Just append() the text nodes:

$('#replyBox').append(quote); 

http://jsfiddle.net/nQErc/

查看更多
登录 后发表回答