[英]Insert value of bootstrap button into textarea doesn't work after click on textarea
I'm using a bootstrap popover wich appears by clicking on a button. 我正在使用通过单击按钮出现的引导程序弹出窗口。 In this popover again there're another buttons with different values, like this one.
再次在此弹出窗口中,有另一个具有不同值的按钮,例如这个。
<button type="button" class="btn btn-default conditions topList" value="move();" id="move">move</button>
My aim is to insert the value of these buttons into a textarea. 我的目的是将这些按钮的值插入文本区域。 For that I'm using the following jQuery:
为此,我使用以下jQuery:
$(document).bind("click", function(e) {
if ((e.target.value != undefined) && (e.target.id != "textarea"))
$('#textarea').append(e.target.value+'\n');
});
Because I want a line skip after each button's value I append an '\\n'. 因为我想在每个按钮的值之后跳过一行,所以我附加了一个'\\ n'。 To ensure that only the values of the buttons are going to be insert into textarea, I avoid to append a value if it's undefined, like when I'm clicking anywhere on the document, where's no button.
为了确保仅将按钮的值插入到textarea中,如果未定义该值,则避免添加它,例如,当我在文档上的任意位置单击时,没有按钮。 So do I by clicking on the textarea.
我也可以单击文本区域。 Without that there'd be a line skip every time i click on the textarea.
否则,每次我单击文本区域时都会跳过一行。
Well, inserting the values works fine, BUT only when I'm not going to click into the textarea. 好吧,插入值可以正常工作,但是仅当我不打算单击文本区域时才可以。 After I clicked once into the textarea, there'll be no reaction by clicking on the buttons.
单击一次文本区域后,单击按钮将没有任何反应。 Same story, when I manually clear the textarea with
$('#textarea').val('')
After that, nothing happens by clicking the buttons. 同一个故事,当我使用
$('#textarea').val('')
手动清除文本区域之后,单击按钮将什么也没有发生。
Any idea? 任何想法?
Thx for the hint with the .val()
. Thx以
.val()
作为提示。
I changed the $('#textarea').append(e.target.value+'\\n');
我更改了
$('#textarea').append(e.target.value+'\\n');
to $('#textarea').val($('#textarea').val() + e.target.value+'\\n');
到
$('#textarea').val($('#textarea').val() + e.target.value+'\\n');
Now it's working! 现在工作了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.