Knockout textInput and maskedinput plugin

前端 未结 1 1029
小鲜肉
小鲜肉 2021-01-23 22:21

Is there an easy way to use data-bind=\"textInput: aProperty\" and add an input mask or some automatic formatting as the user types?

Using the mask

相关标签:
1条回答
  • 2021-01-23 22:56

    I've written a fiddle that uses just a computed observable, and I don't have a focus problem with it. Does this work as you expect?

    var displayString = ko.observable('');
    var formattedString = ko.computed({
        read: function () {
            return displayString();
        },
        write: function (newValue) {
            var f = format(newValue);
            console.debug("Format", newValue, "=", f);
            displayString(f);
        }
    });
    

    http://jsfiddle.net/csmmnq25/

    0 讨论(0)
提交回复
热议问题