How to count words in JavaScript using JQuery

前端 未结 7 1226
旧巷少年郎
旧巷少年郎 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:51

    var str = $('#name').val(),
        count = str.split(' ').length;
    

    Assuming that each word is seperated by a space

提交回复
热议问题