<p class="chart z">
今日:
<em>8</em>
<span class="pipe">|</span>
昨日:
<em>11</em>
<span class="pipe">|</span>
帖子:
<em>95</em>
<span class="pipe">|</span>
会员:
<em>41</em>
<span class="pipe">|</span>
欢迎新会员:
<em>
<a class="xi2" target="_blank" href="space-username-vling5.html">vling5</a>
</em>
</p>
我想从html里得到一个数组,里面是 8,11,95,41应该怎么写呢?急

解决方案 »

  1.   

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title>
    <style>
    body {font-size:12px;}
    </style>
    </head>
    <body>
    <div id="t">
    <p class="chart z">
    今日:
    <em>8</em>
    <span class="pipe">|</span>
    昨日:
    <em>11</em>
    <span class="pipe">|</span>
    帖子:
    <em>95</em>
    <span class="pipe">|</span>
    会员:
    <em>41</em>
    <span class="pipe">|</span>
    欢迎新会员:
    <em>
    <a class="xi2" target="_blank" href="space-username-vling5.html">vling5</a>
    </em>
    </p>
    </div>
    <script>
    function $(el){
    return typeof el == 'string' ? document.getElementById(el) : el;
    }
    var s = $('t').innerHTML;
    var re = /<em>(\d+)<\/em>/g;
    var s = s.match(re).join(',').replace(/[^\d,]/g, '');
    alert(s.split(','))
    </script>
    </body>
    </html>
    楼主 这个意思?
      

  2.   

    就是三楼的效果了,不过我这里测试只能firefox能用,IE包s.match( 为null
      

  3.   

    改下
    var re = /<em>(\d+)<\/em>/gi;