读书人

急求正则解决解决方案

发布时间: 2012-04-15 18:39:21 作者: rapoo

急求正则解决

HTML code
<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应该怎么写呢?急

[解决办法]
HTML code
<!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> 

读书人网 >JavaScript

热点推荐