jQuery: Count words in real time

后端 未结 2 988
抹茶落季
抹茶落季 2020-12-03 22:37

I am using the following jQuery functionality to count words in real time:

$(\"input[type=\'text\']:not(:disabled)\").each(function(){
            var input          


        
2条回答
  •  自闭症患者
    2020-12-03 22:53

    Edit

    Check this example.


    Why don't you use split(" ") instead of matching and dividing the result? You will have an array containing all your words, the length of the array will be the number of words.

    var matches = $(field).val().split(" ");
    

    Also, why are you adding every time the matches to the old result?

    $('#finalcount').val(original_count + number)
    

    Isn't this adding every time all the words twice?

提交回复
热议问题