jQuery 페이지 또는 객체에서 특정 키워드 강조하기
Open API/Jquery2016. 11. 17. 10:59
반응형
특정 페이지 또는 객체에서 키워드 찾는 함수..
1원짜리는 아니고...3원쯤의 가치가..;;
Test Url : http://www.uhoon.co.kr/test/3143.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>KeyWord Highlights</title>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
</head>
<script type="text/javascript">
<!--
$(document).ready(function(){
fnKeyWordHighlights("p","감기");
});
function fnKeyWordHighlights(obj,keyword)
{
$(obj).each(function(){
$(this).html($(this).html().replace(eval("/"+keyword+"/gi"), "<span style='color:red;font-weight:bold;'>"+keyword+"</span>"));
});
}
//-->
</script>
</head>
<body >
<p>나는 오늘 감기에 걸렸다. 지겨운 감기.. 너무 싫다.</p>
</body>
</html>
댓글()







