日期:2014-05-16  浏览次数:20412 次

怎么把这样的格式 按指定要求输出?
本帖最后由 lyshrine 于 2013-07-30 14:16:44 编辑
后台传的一个字符串
12131800011   21W37990162               1HKG                Y032204      20100921095059220400Y03                                                                                            20100929165532I

每个之间有不定长的多个空格,怎么才能去掉中间的空格,并居左换行显示,
需要这样的效果:
12131800011
21W37990162
1HKG
Y032204
20100921095059220400Y03
20100929165532I
请问如何实现?

------解决方案--------------------
正则替换空格为逗号,然后split分隔字符串得到字符数组
var strArrary = str.replace(/\s*/,",").split(",");
------解决方案--------------------
<div id="dv">12131800011   21W37990162               1HKG                Y032204      20100921095059220400Y03                                                                                            20100929165532I</div>
<script>
    window.onload = function () {
        var dv = document.getElementById('dv');
        dv.innerHTML=dv.innerHTML.replace(/\s+/g,'<br/>')