[求助]关于查询字符变色显示的问题
写了一段代码 想实现查找的内容用红字显示,但是发现让特定的字显示为红可以,但不能替换一个变量,请高手指点怎么改function rep(){
function elm(tag){
return document.getElementsByTagName(tag);
}
// var find = elm("p")[0].innerHTML;
var tt=document.getElementById("tt").value //tt代表输入的要查询的字符串
for(i=0;i<=elm("p").length;i++)
{
//var find = elm("p")[i].innerHTML;
elm("p")[i].innerHTML=elm("p")[i].innerHTML.(/(key)/ig,"<strong style='color:red'>"+tt+"</strong>");
//应该是修改上面这段代码中的key部分就好了
}
}
</script>
</HEAD>
<BODY>
<p>test jandy ....... key fdkjslkfkeydjslkf</p>
<p>test jandy ....... key fdkjslkfkeydjslkf</p>
<p>test jandy ....... key fdkjslkfkeydjslkf</p>
<p>test jandy ....... key fdkjslkfkeydjslkf</p>
<input type="text" id="tt">
<input type="button" value="sub" onclick="rep()">
</BODY>
</HTML>