- <!doctype html>
<html lang=
"en"
>
- <head>
<meta charset=
"UTF-8"
/>
<meta http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
/>
<title> 页面名称 </title>
<style type=
"text/css"
>
- #edit span {
background:
#FFFF00;
- }
- </style>
- </head>
- <body>
<div><h4>你查询的词是</h4><input type=
"text"
class=
"ss"
id=
"text"
/><input type=
"button"
value=
"搜索"
class=
"btn_ss"
onclick=
"sf()"
/></div>
<div id=
"edit"
contentEditable=
"true"
>
lication.These techniques allow a VM to dynamically translate a pro-gram to nested, type-specialized trace trees.
- </div>
<script type=
"text/javascript"
>
function
sf() {
var
reg = document.getElementById(
"text"
).value.replace(/[\.\\\/\|\(\)\[\]\{\}\?\+\*\^\$\
"\']/g,"
\\$&
");
var html = document.getElementById("
edit
").innerHTML.replace(/<\/?span>/ig,"
");
document.getElementById("
edit
").innerHTML = html.replace(new RegExp(reg,"
ig
"),"
<span>$&</span>");
- }
- </script>
</body>
</html>
jquery获取相同的内容并且高亮
最新推荐文章于 2020-04-14 14:31:43 发布