How do you get the length of a string?

后端 未结 10 1530
星月不相逢
星月不相逢 2020-12-12 12:43

How do you get the length of a string in jQuery?

10条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 13:14

    A somewhat important distinction is if the element is an input or not. If an input you can use:

    $('#selector').val().length;
    

    otherwise if the element is a different html element like a paragraph or list item div etc, you must use

    $('#selector').text().length;
    

提交回复
热议问题