[JavaScript] 截取字符串长短-js →→→→→进入此内容的聊天室

来自 , 2020-08-14, 写在 JavaScript, 查看 105 次.
URL http://www.code666.cn/view/c058f544
  1. //fn: 截取字符串长短
  2.             function fnSubString(oldStr, requireLength, endWith) {
  3.                 //1.oldStr是否可用
  4.                 if (typeof oldStr == "string") {
  5.                     if ((oldStr.length < 1) || (oldStr.length <= requireLength)) {
  6.                         return oldStr;
  7.                     }
  8.                     if (oldStr.length > requireLength) {
  9.                         //判断endwith是否可用
  10.                         return ((typeof endWith == "string") ? oldStr.substr(0, requireLength) + endWith + "" : oldStr.substr(0, requireLength) + "");
  11.                     }
  12.                 } else {
  13.                     //判断endwith是否可用;仅仅显示"...",表示oldStr不可用
  14.                     return ((typeof endWith == "string") ? endWith + "" : "...");
  15.                 }
  16.             }
  17.  
  18.  
  19.  
  20. //fn: 截取字符串长短
  21. function fnSubString(oldStr, requireLength, endWith) {
  22.     //设置参数格式
  23.     oldStr += "";
  24.     endWith += "";
  25.     requireLength = parseInt(requireLength + "", 10);
  26.  
  27.     if ((oldStr.length < 1) || (oldStr.length <= requireLength)) {
  28.         return oldStr;
  29.     }
  30.     if (oldStr.length > requireLength) {
  31.         //判断endwith是否可用
  32.         return ((typeof endWith == "string") ? oldStr.substr(0, requireLength) + endWith + "" : oldStr.substr(0, requireLength) + "");
  33.     }
  34. }
  35.  
  36. //fn: 截取字符串长短
  37. function fnSubString(oldStr, requireLength, endWith) {
  38.     //设置参数格式
  39.     oldStr += "";
  40.     endWith += "";
  41.     requireLength = parseInt(requireLength + "", 10);
  42.  
  43.     if ((oldStr.length < 1) || (oldStr.length <= requireLength)) {
  44.         return oldStr;
  45.     }
  46.     if (oldStr.length > requireLength) {
  47.         return oldStr.substr(0, requireLength) + endWith;
  48.     }
  49. }
  50.  

回复 "截取字符串长短-js"

这儿你可以回复上面这条便签

captcha