Wie kann ich weitere Eingaben im Textbereich mit maxlength @ blockiere

Ich habe ein Textfeld, für das ich die Eingabe blockieren möchte, wenn die eingegebenen Zeichen eine maximale Länge erreichen.

Ich habe derzeit ein JQuery-Skript für das Textfeld, das die eingegebenen Zeichen berechnet, und möchte etwas hinzufügen, das die Eingabe im Textbereich blockiert, sobald 150 Zeichen eingegeben wurden.

Ich habe versucht, Plugins mit maximaler Länge in Verbindung mit meinem Skript zu verwenden, aber sie scheinen nicht zu funktionieren. Hilfe wird geschätzt.

AKTUELLER CODE

(function($) {
    $.fn.charCount = function(options){
        // default configuration properties
        var defaults = {    
            allowed: 150,       
            warning: 25,
            css: 'counter',
            counterElement: 'span',
            cssWarning: 'warning',
            cssExceeded: 'exceeded',
            counterText: '',
            container: undefined // New option, accepts a selector string
        }; 

        var options = $.extend(defaults, options); 

        function calculate(obj,$cont) {
              // $cont is the container, now passed in instead.
            var count = $(obj).val().length;
            var available = options.allowed - count;
            if(available <= options.warning && available >= 0){
                $cont.addClass(options.cssWarning);
            } else {
                $cont.removeClass(options.cssWarning);
            }
            if(available < 0){
                $cont.addClass(options.cssExceeded);
            } else {
                $cont.removeClass(options.cssExceeded);
            }
            $cont.html(options.counterText + available);
        };

        this.each(function() {
         // $container is the passed selector, or create the default container
            var $container = (options.container)
                    ? $(options.container)
                        .text(options.counterText)
                        .addClass(options.css)
                    : $('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>').insertAfter(this);
            calculate(this,$container);
            $(this).keyup(function(){calculate(this,$container)});
            $(this).change(function(){calculate(this,$container)});
        });

    };
})(jQuery);

Antworten auf die Frage(10)

Ihre Antwort auf die Frage