将文本添加到 textarea - Jquery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7058864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:21:33 来源:igfitidea点击:
Add text to textarea - Jquery
提问by Oliver 'Oli' Jensen
How can I add text from a DIV to a textarea?
如何将文本从 DIV 添加到文本区域?
I have this now:
我现在有这个:
$('.oquote').click(function() {
$('#replyBox').slideDown('slow', function() {
var quote = $('.container').text();
$('#replyBox').val($('#replyBox').val()+quote);
// Animation complete.
});
});
回答by AlienWebguy
Just append()
the text nodes:
只是append()
文本节点:
$('#replyBox').append(quote);
回答by Felix Kling
That should work. Better if you pass a function to val
:
那应该工作。如果您将函数传递给val
:
$('#replyBox').val(function(i, text) {
return text + quote;
});
This way you avoid searching the element and calling val
twice.
这样您就可以避免搜索元素并调用val
两次。