当我在textarea中输入时,KnockoutJS绑定到div

TGH*_*TGH 3 javascript asp.net knockout.js

是否可以在Knockout中在文本区域和页面上的DIV之间进行"实时"绑定,每次textarea的内容发生更改(每个字符的字符)时更新DIV?我在我的视图模型上使用了一个计算字段,但它不会更新DIV,除非我选中了textarea:是否可以在每次更改时立即更新它,而不必关闭标签?

function EditModel() {
        this.CommentTextPlain = ko.observable("");

        var self = this;

        this.CommentReady = ko.computed(function () {
            return self.CommentTextPlain().replace(regex, "<BR>");
        });
    }

    function ApplyViewmodel() {
        model = new EditModel();
        ko.applyBindings(model, document.getElementById("mainContainer"));
    }

<div id="mainContainer">
    <div id="target" data-bind='html: CommentReady' class="commentEditBox"></div> 

    <textarea data-bind="value: CommentTextPlain" rows="20" cols="62" id="editBoxFull">    </textarea>

</div>
Run Code Online (Sandbox Code Playgroud)

RP *_*yer 6

value绑定有一个叫做伴侣的选择valueUpdate,你可以设置为包括像其他事件:

data-bind="value: CommentTextPlain, valueUpdate: 'afterkeydown'"
Run Code Online (Sandbox Code Playgroud)