Jquery calculated value of the text field

Jquery calculated value of the text field

('.sr').on('keyup','#sr_txt',function(){
    if($(this).val().length > 100){
        $(this).val( $(this).val().substring(0,100) );
    }
        $(".sr_span span").html(100 - $(this).val().length) ;
})

The following describes the idea of
the method employed herein event delegate
$ ( 'parent') .on ( "event name", "element to be operated ', function () {
})
determines whether the current character is greater than the length of the element 100.
With substring (0,100) method represents between 0-100 characters
below to show how many characters

Guess you like

Origin blog.csdn.net/qq_44306441/article/details/89421486