如何实现控件+查找与浏览器相同的功能到特定的div [英] how to implement control+find functionality same as browser to a particular div
本文介绍了如何实现控件+查找与浏览器相同的功能到特定的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有一些文本的div和一个div上面的文本框,我想每当用户键入一些文本时,用户输入的文本应该是突出显示它也应该显示macthing记录的数量为(2/20)与我们在浏览器中按ctl + f时的操作相同。
我有发现突出显示jquery插件,但它确实没有显示记录为(2 of 20)。只是突出显示文本。
Hi,
I have a div with some text and a textbox above that div ,i want whenever user type some text ,the text enetered by the user should be highlighted and it should also show number of macthing records as ( 2 of 20) same as what we do in a browser when we press ctl+f .
I have found highlight jquery plugin but it does show no of records as (2 of 20 ) .it just highlight text.
jQuery.fn.highlight = function (pat) {
function innerHighlight(node, pat) {
var skip = 0;
if (node.nodeType == 3) {
var pos = node.data.toUpperCase().indexOf(pat);
if (pos >= 0) {
var spannode = document.createElement('span');
spannode.className = 'highlight';
var middlebit = node.splitText(pos);
var endbit = middlebit.splitText(pat.length);
var middleclone = middlebit.cloneNode(true);
spannode.appendChild(middleclone);
middlebit.parentNode.replaceChild(spannode, middlebit);
skip = 1;
}
}
else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
for (var i = 0; i < node.childNodes.length; ++i) {
i += innerHighlight(node.childNodes[i], pat);
}
}
return skip;
}
return this.each(function () {
innerHighlight(this, pat.toUpperCase());
});
};
推荐答案
这篇关于如何实现控件+查找与浏览器相同的功能到特定的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文