标签:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>检索关键字</title>
</head>
<body>
<div id="content">
www.js.108<br />
bbs.108js.com<br />
javascript is not java<br />
javascript is fun and i love javascript
</div>
<div>
<input type="text" id="keyword" />
<button onclick="match()">Search</button>
</div>
<script type="text/javascript">
var str = content.innerHTML;
var keyword = document.getElementById("keyword");
var contents = document.getElementById("content");
function match(){
if(keyword.value==‘‘)return false;
var regxp = new RegExp("("+keyword.value+")","g");
var val = contents.innerText;
//alert(val.indexOf(keyword.value));
//alert(contents.innerText.indexOf(keyword.value));
if(contents.innerText.indexOf(keyword.value)==-1)alert("未知参数");
content.innerHTML=str.replace(regxp,"<font color=‘red‘>$1</font>")
}
</script>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/yifeizeng168/p/5011602.html