<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<script>
function find(){var lis=document.getElementsByTagName('li');
var patt=/\w+@\w+(\.\w+)+/;
var i=0;console.log(lis.length);
console.log(lis[1].innerHTML);
while(i<lis.length){
if(patt.exec(lis[i].innerText)){
lis[i].style.background='yellow';
}
i++;
}
}
</script></head>
<body>
<input type="button" value="标注有邮箱的人" onclick="find();" />
<ul>
<li>张飞</li>
<li>刘备&lt;[email protected]&gt;</li>
<li>关羽</li>
<li>赵云&lt;[email protected]&gt;</li>
</ul>
</body>
</html>

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
    <head>
    <title>新建网页</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="" />
    <script>
    function find(){
    var lis=document.getElementsByTagName('li');
    var patt=/\w+@\w+(\.\w+)+/;
    var i=0;
    while(i<lis.length){
    if(patt.test(lis[i].innerHTML)!==false){
    lis[i].style.background='yellow';
    }
    i++;
    }
    }
    </script></head>
    <body>
    <input type="button" value="标注有邮箱的人" onclick="find();" />
    <ul>
    <li>张飞</li>
    <li>刘备&lt;[email protected]&gt;</li>
    <li>关羽</li>
    <li>赵云&lt;[email protected]&gt;</li>
    </ul>
    </body>
    </html>