0

当在 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);
});
4

2 回答 2

4

您的代码正在运行,您可能需要将其放在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>
于 2013-08-19T10:53:18.697 回答
0

将类“txtspeech”添加到要显示文本的 div

于 2013-08-19T10:53:49.590 回答