本文介绍了输入时将文本框值附加到textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当按下按钮时,我希望将textbox
值附加到textarea
的新行上.我已经可以使用了,但是我不确定如何附加textbox
值.我尝试了一些东西,但是没用.
When the button is pressed, I'd like the textbox
value to be appended on a new line to a textarea
. I've already got the working but I'm not sure how to append the textbox
value. I tried something but it didn't work.
$(function() {
$("#quickLinksTextbox input").keypress(function (e) {
if (e.keyCode == 13) {
$("#quickLinksURLs").val().append("#quickLinksSave");
}
});
});
推荐答案
检查我的代码.
$(document).on('keypress', '#quickLinksTextbox input', function (e){
var inputEl = $(this);
var textareaEl = $('#quickLinksURLs');
//Enter was pressed
if(e.keyCode == 13){
//If input have any text
if($(inputEl).val().length){
//Appending current content from input (with new line ending) to textarea
$(textareaEl).val($(textareaEl).val()+$(inputEl).val()+"\r\n");
//Cleaning input
$(inputEl).val('');
}
return false;
}
});
这篇关于输入时将文本框值附加到textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!