js判断字符串str是否包含字符串substr: function addUser(id,realName){ var userids = $("#userids").val(); if (userids!=""&&userids!=null) { if (!isContains(userids,id)) { userids = userids + id + ","; } }else{ userids = id + ",
首先看看判断字符串长度的几种方法(英文占1个字符,中文汉字占2个字符) 方法一: function strlen(str) { var len = 0; for (var i = 0; i < str.length; i++) { var c = str.charCodeAt(i); //单字节加1 if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) { len++