日期:2014-05-16 浏览次数:20325 次
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> 待测文本<div id="str"><li><a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" target="_blank">顶顶顶顶</a></li></div> 输入正则<textarea id="test"></textarea> <button id="btn">点击</button> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } $('btn').onclick = function(){ var re = $('test').value; var s = $('str').innerHTML var r = new RegExp(re, 'i') alert( s.match(r) ) } </script> </body> </html>