高亮显示关键字

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>

你可能感兴趣的:(关键字)