Jquery mark.js-使用下一个/上一个/清除函数突出显示URL引用者

Jquery mark.js-使用下一个/上一个/清除函数突出显示URL引用者,jquery,highlight,referrer,Jquery,Highlight,Referrer,我想实现突出显示,以便来自我的谷歌自定义搜索引擎的搜索词将被突出显示。这可以按照为“URL引用者突出显示”提供的示例进行。我希望能够添加下一个/上一个和清除功能,以帮助用户单击匹配项,并更改搜索条件,如“带跳转到匹配项的搜索栏”示例中所示。我一直无法让它工作。。。有人能帮忙吗 下面是一个URL引用者的工作列表,突出显示: 我想加入下一个|上一个|清除按钮,让用户在搜索匹配中按自己的方式工作 上一个/下一个/清除功能有一把小提琴: 他们使用的代码是: $(function() {

我想实现突出显示,以便来自我的谷歌自定义搜索引擎的搜索词将被突出显示。这可以按照为“URL引用者突出显示”提供的示例进行。我希望能够添加下一个/上一个和清除功能,以帮助用户单击匹配项,并更改搜索条件,如“带跳转到匹配项的搜索栏”示例中所示。我一直无法让它工作。。。有人能帮忙吗

下面是一个URL引用者的工作列表,突出显示:

我想加入下一个|上一个|清除按钮,让用户在搜索匹配中按自己的方式工作

上一个/下一个/清除功能有一把小提琴:

他们使用的代码是:

    $(function() {

      // the input field
      var $input = $("input[type='search']"),
    // clear button
    $clearBtn = $("button[data-search='clear']"),
    // prev button
    $prevBtn = $("button[data-search='prev']"),
    // next button
    $nextBtn = $("button[data-search='next']"),
    // the context where to search
    $content = $(".content"),
    // jQuery object to save <mark> elements
    $results,
    // the class that will be appended to the current
    // focused element
    currentClass = "current",
    // top offset for the jump (the search bar)
    offsetTop = 50,
    // the current index of the focused element
    currentIndex = 0;

    /**
     * Jumps to the element matching the currentIndex
    */
    function jumpTo() {
        if ($results.length) {
          var position,
            $current = $results.eq(currentIndex);
          $results.removeClass(currentClass);
          if ($current.length) {
            $current.addClass(currentClass);
            position = $current.offset().top - offsetTop;
            window.scrollTo(0, position);
          }
        }
      }

    /**
    * Searches for the entered keyword in the
    * specified context on input
    */
    $input.on("input", function() {
    var searchVal = this.value;
    $content.unmark({
    done: function() {
    $content.mark(searchVal, {
              separateWordSearch: true,
              done: function() {
                $results = $content.find("mark");
                currentIndex = 0;
                jumpTo();
              }
            });
          }
      });
    });

    /**
    * Clears the search
    */
    $clearBtn.on("click", function() {
    $content.unmark();
    $input.val("").focus();
      });

      /**
       * Next and previous search jump to
       */
      $nextBtn.add($prevBtn).on("click", function() {
        if ($results.length) {
          currentIndex += $(this).is($prevBtn) ? -1 : 1;
          if (currentIndex < 0) {
            currentIndex = $results.length - 1;
          }
          if (currentIndex > $results.length - 1) {
            currentIndex = 0;
          }
          jumpTo();
        }
      });
    });
$(函数(){
//输入字段
var$input=$(“input[type='search']),
//清除按钮
$clearBtn=$(“按钮[data search='clear']),
//上一个按钮
$prevBtn=$(“按钮[data search='prev']),
//下一个按钮
$nextBtn=$(“按钮[data search='next']),
//要搜索的上下文
$content=$(“.content”),
//用于保存元素的jQuery对象
$results,
//将附加到当前对象的类
//聚焦元件
currentClass=“当前”,
//跳转的顶部偏移(搜索栏)
偏移量=50,
//聚焦元素的当前索引
currentIndex=0;
/**
*跳转到与currentIndex匹配的元素
*/
函数jumpTo(){
如果($results.length){
var位置,
$current=$results.eq(currentIndex);
$results.removeClass(currentClass);
如果($current.length){
$current.addClass(currentClass);
位置=$current.offset().top-offsetTop;
滚动到(0,位置);
}
}
}
/**
*在中搜索输入的关键字
*输入时指定的上下文
*/
$input.on(“输入”,函数(){
var searchVal=this.value;
$content.unmark({
完成:函数(){
$content.mark(searchVal{
separateWordSearch:对,
完成:函数(){
$results=$content.find(“标记”);
currentIndex=0;
跳到();
}
});
}
});
});
/**
*清除搜索
*/
$clearBtn.on(“单击”,函数(){
$content.unmark();
$input.val(“”.focus();
});
/**
*下一个和上一个搜索跳转到
*/
$nextBtn.add($prevBtn).on(“单击”,函数()){
如果($results.length){
currentIndex+=$(this).is($prevBtn)?-1:1;
如果(当前索引<0){
currentIndex=$results.length-1;
}
如果(当前索引>$results.length-1){
currentIndex=0;
}
跳到();
}
});
});

n您能否添加可能有助于我们帮助您的代码out@ankitverma我在问题中添加了小提琴的链接和下一个/上一个/清除函数的代码。提前感谢您在这方面给予我的任何帮助!