//fn: 截取字符串长短 |
function fnSubString(oldStr, requireLength, endWith) { |
//1.oldStr是否可用 |
if ( typeof oldStr == "string" ) { |
if ((oldStr.length < 1) || (oldStr.length <= requireLength)) { |
return oldStr; |
} |
if (oldStr.length > requireLength) { |
//判断endwith是否可用 |
return (( typeof endWith == "string" ) ? oldStr.substr(0, requireLength) + endWith + "" : oldStr.substr(0, requireLength) + "" ); |
} |
} else { |
//判断endwith是否可用;仅仅显示"...",表示oldStr不可用 |
return (( typeof endWith == "string" ) ? endWith + "" : "..." ); |
} |
} |
//fn: 截取字符串长短 |
function fnSubString(oldStr, requireLength, endWith) { |
//设置参数格式 |
oldStr += "" ; |
endWith += "" ; |
requireLength = parseInt(requireLength + "" , 10); |
if ((oldStr.length < 1) || (oldStr.length <= requireLength)) { |
return oldStr; |
} |
if (oldStr.length > requireLength) { |
//判断endwith是否可用 |
return (( typeof endWith == "string" ) ? oldStr.substr(0, requireLength) + endWith + "" : oldStr.substr(0, requireLength) + "" ); |
} |
} |
//fn: 截取字符串长短 |
function fnSubString(oldStr, requireLength, endWith) { |
//设置参数格式 |
oldStr += "" ; |
endWith += "" ; |
requireLength = parseInt(requireLength + "" , 10); |
if ((oldStr.length < 1) || (oldStr.length <= requireLength)) { |
return oldStr; |
} |
if (oldStr.length > requireLength) { |
return oldStr.substr(0, requireLength) + endWith; |
} |
} |