当文本在Textarea中输入,然后在DIV中显示文本,但条件是,我追加多个DIV,然后在Textare中键入文本,然后仅显示一个DIV而不显示其他DIV 。如何在div中显示文本,当文本在Textarea中输入时
我的代码:
<button data-bind="adds">ADD</button>
<div data-bind="foreach: items">
<div class="SpeechBubble" id="speechID" data-bind="attr: { class: 'SpeechBubble' }">
<div class="pointer bottom " id="pointer"></div>
<div class="txtspeech"></div>
</div>
</div>
var SpeechBubble = function() {
this.items = ko.observableArray();
this.adds = function (item) {
this.items.push(item);
}
}
ko.applyBindings(new SpeechBubble());
$('.speechttxt').keyup(function() {
var txt = $(this).val();
$('.txtspeech').html(txt);
});
你如何确定哪些'div'改变的文本? –
当我追加第一个div然后在文本区域显示在DIV中键入文本。 – user2645731
对,但是如果再次追加,应该更改哪个div?前一个,还是新的? –