<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title><script type="text/javascript">function SearchCompare() {// 获取搜索字符串var searchText = document.getElementById("SearchCompare.Text").value;// 根据开始和结束标记来进行循环var begin = 1;var end = 7;for (var i = begin; i < end; i++) {// 拼接Element元素的名称var itemName = "li" + i;var itemContent = document.getElementById(itemName).innerText;if(itemContent.indexOf(searchText) > -1){// 设置该元素的背景色为红色document.getElementById(itemName).style.backgroundColor="#f00";}}alert(document.getElementById("SearchCompare.Text").value);}</script></head><body><input type="text" id="SearchCompare.Text" /><input type="button" id="SearchCompare.Button" value="查找" οnclick="SearchCompare()" /><ul>张三<li><a href="#" id="li1">AB</a></li><li><a href="#" id="li2">BC</a></li><li><a href="#" id="li3">CC</a></li><li><a href="#" id="li4">DA</a></li><li><a href="#" id="li5">EA</a></li><li><a href="#" id="li6">FCB</a></li></ul></body></html>