js判断字符串str是否包含字符串substr
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 + ","; } $("#userids").val(userids); var realnames = $("#realnames").val(); if (realnames!=""&&realnames!=null) { if (!isContains(realnames,realName)) { realnames = realnames + realName + ","; } }else{ realnames = realName + ","; } $("#realnames").val(realnames); } //判断str中是否包含substr function isContains(str, substr) { return str.indexOf(substr) >= 0; }