简体   繁体   English

在Textarea中输入文本时,如何在div中显示文本

[英]How to show text in div, when text enter in Textarea

When Text Enter in Textarea then show text in DIV.but Condition is that,i append mutiple DIV then type text in Textare.then show text only one DIV not Other DIV. 当在Textarea中输入文本时,在DIV中显示文本。但条件是,我追加了多个DIV,然后在Textare中键入文本。然后仅显示一个DIV,而未显示其他DIV。

My Code : 我的代码:

<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);
});

Your code is working your probably need to put it document.ready so that when the script for binding event is execute the element you are looking for is added to DOM and include jQuery 您的代码正在运行,可能需要将其放入document.ready,以便在执行绑定事件的脚本时,将您要查找的元素添加到DOM包含jQuery

Live Demo 现场演示

$('.speechttxt').keyup(function () {
    var txt = $(this).val();
    $('.txtspeech').html(txt);
});

You can add jQuery using script tag. 您可以使用脚本标签添加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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM