angularjs force uppercase in textbox

前端 未结 14 1832
情歌与酒
情歌与酒 2020-11-30 20:47

I\'ve tried using the uppercase filter but it does not work. I\'ve tried doing it two ways:


<         


        
14条回答
  •  天涯浪人
    2020-11-30 21:25

    If you want to change model and value, use:

    angular.module('MyApp').directive('uppercased', function() {
        return {
            require: 'ngModel',
            link: function(scope, element, attrs, ngModel) {
                element.bind("blur change input", function () {
                    ngModel.$setViewValue($(this).val().toUpperCase());
                    $(this).val($(this).val().toUpperCase());
                });
                element.css("text-transform","uppercase");
            }
        };
    });
    

    Then add uppercased to your html input text

    
    

提交回复
热议问题