Add text to textarea - Jquery

心不动则不痛 提交于 2019-11-27 02:29:29

问题


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.
      });    
    });

回答1:


Just append() the text nodes:

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

http://jsfiddle.net/nQErc/




回答2:


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.



来源:https://stackoverflow.com/questions/7058864/add-text-to-textarea-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!