How to count words in JavaScript using JQuery

前端 未结 7 1199
旧巷少年郎
旧巷少年郎 2020-12-09 13:17

I have a simple html text box. When I \"submit\" the form that the text box is in, I would like to get a variable with the number of words inside using Jqu

7条回答
  •  自闭症患者
    2020-12-09 13:42

    Try this to count words in JavaScript using JQuery.

    $(document).ready(function(){
        $("button").click(function(){
            var words = $.trim($("#name").val()).split(" ");
            alert(words.length);
        });
    });
    

    See more @ Count words in JavaScript using JQuery

提交回复
热议问题