js-检索文字高亮显示

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.1.min.js"></script>
<script>
$(function(){
$("#codearea").bind("click",function(){getSelect($("#codearea"))});
$("#codearea").children().each(function(){
$(this).bind("click",function(){getSelect(this)});
})
})
 function getSelect(obj)
    {
        if(window.getSelection)
        {
var count=0;
var code=window.getSelection()+"";
            if(undefined!=code&&0!=code.length&&""!=code){
var codehtml=$(obj).text();
var newhtml=""
for(var i=0;i<codehtml.length;i++){
var newcode=codehtml.substring(i,i+code.length);
if(code==newcode){
newhtml+="<span style='color:red'>"+newcode+"</span>";
i=i+code.length;
count++;
}else{
newhtml=newhtml+codehtml.substring(i,i+1);
}
}
$(obj).text("");
$(obj).html(newhtml);
alert("共检索到"+count+"条")
}
        }
        else
        {
alert("====")
            alert(document.selection.createRange().text);
        }
        
    }
</script>
<p>js-鼠标左击选中文件检索全文</p>
<div id="codearea">
<div>
List 111111111111111111 logo
</div>
@Test public void shouldDecapitalizeSomeCharsUntilItFindsOneUppercased() throws NoSuchMethodException {
  Assert.assertEquals("urlClassLoader",extractor.nameFor(URLClassLoader.class));
  Assert.assertEquals("bigDecimal",extractor.nameFor(BigDecimal.class));
  Assert.assertEquals("string",extractor.nameFor(String.class));
  Assert.assertEquals("aClass",extractor.nameFor(AClass.class));
  Assert.assertEquals("url",extractor.nameFor(URL.class));
}
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值