Home > Web Front-end > JS Tutorial > js left, right, mid function_javascript skills

js left, right, mid function_javascript skills

WBOY
Release: 2016-05-16 19:03:49
Original
2216 people have browsed it

在JAVASCRIPT中LEFT,RIGHT,MID函数的等价函数 

function left(mainStr,lngLen) {
 if (lngLen>0) {return mainStr.substring(0,lngLen)}
 else{return null}
 } 

function right(mainStr,lngLen) {
// alert(mainStr.length)
 if (mainStr.length-lngLen>=0 && mainStr.length>=0 && mainStr.length-lngLen return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
 else{return null}
 }
function mid(mainStr,starnum,endnum){
 if (mainStr.length>=0){
 return mainStr.substr(starnum,endnum)
 }else{return null}
 //mainStr.length
 }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template