当在 Textarea 中输入文本时,然后在 DIV 中显示文本。但条件是,我附加多个 DIV 然后在 Textare 中键入文本。然后仅显示文本一个 DIV 而不是其他 DIV。
我的代码:
<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);
});