[英]How to show text in div, when text enter in Textarea
當在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);
});
您的代碼正在運行,可能需要將其放入document.ready,以便在執行綁定事件的腳本時,將您要查找的元素添加到DOM
並包含jQuery
$('.speechttxt').keyup(function () {
var txt = $(this).val();
$('.txtspeech').html(txt);
});
您可以使用腳本標簽添加jQuery。
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script type="text/javascript">
document.ready(function(){
$('.speechttxt').keyup(function () {
var txt = $(this).val();
$('.txtspeech').html(txt);
});
});
</script>
將類“ txtspeech”添加到要顯示文本的div中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.