js中的split()方法的使

来源:互联网 发布:福禄克网络sn查询 编辑:程序博客网 时间:2024/06/08 08:01

最近遇到字符分隔问题,再此简单的额总结一下:

这里写几个简单的字符串分隔的例子

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>split方法</title></head><body><div class="box"><p id="first"></p><p id="second"></p><p id="third"></p><p id="forth"></p><p id="fifth"></p></div><script type="text/javascript">var str="hello world && good morning";document.getElementById('first').innerHTML=str.split(' ');document.getElementById('second').innerHTML=str.split('');document.getElementById('third').innerHTML=str.split(' ',3);//3可选,表示返回数组的最大长度document.getElementById('forth').innerHTML="2:3:4:5".split(':');document.getElementById('fifth').innerHTML="a|b|c|d|e|f".split('|');</script></body></html>

返回结果如下图:




0 0