make an input only-numeric type on knockout

后端 未结 10 1027
情书的邮戳
情书的邮戳 2020-11-30 06:15

i read many tutorials but i dont know how to do this, this is the input

input(type=\"text\",name=\"price\",id=\"price\"data-bind=\"text: price,valueUpdate:[\         


        
10条回答
  •  庸人自扰
    2020-11-30 06:29

    Best for today's scenerio https://github.com/Knockout-Contrib/Knockout-Validation

    run the snippet below. entering a non digit or something more than 255 will cause the message to display.

    function model() {
      var self = this;
      this.myObj = ko.observable().extend({ digit: true }).extend({ max: 255});
      }
      
      var mymodel = new model();
    
    $(document).ready(function() {
      ko.validation.init();
      ko.applyBindings(mymodel);
    });
    
    
    
    
    enter a digit less than or equal to  255 
    
    

    Enter something other than a digit or over 255 will cause an error.

    courtesy: Bryan Dellinger: https://stackoverflow.com/a/42940109/3868653

提交回复
热议问题