当前位置: 代码迷 >> Web前端 >> 高亮展示关键字
  详细解决方案

高亮展示关键字

热度:317   发布时间:2012-11-03 10:57:43.0
高亮显示关键字
JS:


var old_high_light="";
function HighLight(obj) {
	var orange= document.body.createTextRange();   
	orange.moveToElementText(document.getElementById("city_div"));     //此处为DIV层
	var str=obj.value;
	if(obj.value==""){	
		huifu(old_high_light);
	}
	else
	{		
		huifu(old_high_light);
		while(orange.findText(obj.value)){ 
		   orange.pasteHTML("<span style='color:red;'>" + orange.text + "</span>"); 
	   }
	}
	old_high_light=obj.value;
}

function huifu(old_high_light)
{
   var orange= document.body.createTextRange();   
   orange.moveToElementText(document.getElementById("city_div"));
   if(old_high_light!=""){
	   while(orange.findText(old_high_light)){ 
		 orange.pasteHTML("<span style='color:#000000;'>" + orange.text + "</span>"); 	
	   }   
   }
}

链接那:"<tr><td align=left>关键字查找:</td><td><input type='text' id='CITYSS' size='8' onpropertychange='HighLight(this)' onselectstart='return false'/></td></tr>
  相关解决方案