<legend id='N6YeE'><style id='N6YeE'><dir id='N6YeE'><q id='N6YeE'></q></dir></style></legend>

  • <tfoot id='N6YeE'></tfoot>
  • <small id='N6YeE'></small><noframes id='N6YeE'>

  • <i id='N6YeE'><tr id='N6YeE'><dt id='N6YeE'><q id='N6YeE'><span id='N6YeE'><b id='N6YeE'><form id='N6YeE'><ins id='N6YeE'></ins><ul id='N6YeE'></ul><sub id='N6YeE'></sub></form><legend id='N6YeE'></legend><bdo id='N6YeE'><pre id='N6YeE'><center id='N6YeE'></center></pre></bdo></b><th id='N6YeE'></th></span></q></dt></tr></i><div id='N6YeE'><tfoot id='N6YeE'></tfoot><dl id='N6YeE'><fieldset id='N6YeE'></fieldset></dl></div>
      <bdo id='N6YeE'></bdo><ul id='N6YeE'></ul>

      1. HTML 中的全文搜索忽略标签/&amp;

        时间:2023-07-31
          • <i id='1ujZF'><tr id='1ujZF'><dt id='1ujZF'><q id='1ujZF'><span id='1ujZF'><b id='1ujZF'><form id='1ujZF'><ins id='1ujZF'></ins><ul id='1ujZF'></ul><sub id='1ujZF'></sub></form><legend id='1ujZF'></legend><bdo id='1ujZF'><pre id='1ujZF'><center id='1ujZF'></center></pre></bdo></b><th id='1ujZF'></th></span></q></dt></tr></i><div id='1ujZF'><tfoot id='1ujZF'></tfoot><dl id='1ujZF'><fieldset id='1ujZF'></fieldset></dl></div>
              <tbody id='1ujZF'></tbody>

                • <bdo id='1ujZF'></bdo><ul id='1ujZF'></ul>

                  <small id='1ujZF'></small><noframes id='1ujZF'>

                  <tfoot id='1ujZF'></tfoot>
                • <legend id='1ujZF'><style id='1ujZF'><dir id='1ujZF'><q id='1ujZF'></q></dir></style></legend>

                  本文介绍了HTML 中的全文搜索忽略标签/&amp;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最近看到了很多用于在 HTML 页面中搜索和突出显示术语的库.但是,我看到的每个库都有同样的问题,他们找不到部分包含在 html 标记中的文本和/或他们无法找到 & 表示的特殊字符.

                  I've recently seen a lot of libraries for searching and highlighting terms within an HTML page. However, every library I saw has the same problem, they can't find text partly encased in an html tag and/or they'd fail at finding special characters which are &-expressed.

                  示例:

                  <span> This is a test. This is a <b>test</b> too</span>
                  

                  搜索测试";会找到第一个实例,但不会找到第二个.

                  Searching for "a test" would find the first instance but not the second.

                  示例b:

                  <span> Pencils in spanish are called l&aacute;pices</span>
                  

                  搜索lápices"或lapices"将无法产生结果.

                  Searching for "lápices" or "lapices" would fail to produce a result.

                  有没有办法绕过这些障碍?

                  Is there a way to circumvent these obstacles?

                  提前致谢!

                  推荐答案

                  你可以使用window.find() 在非 IE 浏览器和 TextRangefindText() 方法.这是一个例子:

                  You can use window.find() in non-IE browsers and TextRange's findText() method in IE. Here's an example:

                  http://jsfiddle.net/xeSQb/6/

                  不幸的是,在版本 15 中切换到 Blink 渲染引擎之前的 Opera 不支持 window.findTextRange.如果您对此感到担忧,一个相当重量级的替代方案是使用 TextRange 和我的 Rangy 库,如下例所示:http://rangy.googlecode.com/svn/trunk/demos/textrange.html

                  Unfortunately Opera prior to the switch to the Blink rendering engine in version 15 doesn't support either window.find or TextRange. If this is a concern for you, a rather heavyweight alternative is to use a combination of the TextRange and CSS class applier modules of my Rangy library, as in the following demo: http://rangy.googlecode.com/svn/trunk/demos/textrange.html

                  以下代码是对上述小提琴的改进,每次执行新搜索时不突出显示以前的搜索结果:

                  The following code is an improvement of the fiddle above by unhighlighting the previous search results each time a new search is performed:

                  function doSearch(text,color="yellow") {
                      if (color!="transparent") {
                        doSearch(document.getElementById('hid_search').value,"transparent"); 
                        document.getElementById('hid_search').value = text; 
                        }
                      if (window.find && window.getSelection) {
                          document.designMode = "on";
                          var sel = window.getSelection();
                          sel.collapse(document.body, 0);
                          
                          while (window.find(text)) {
                              document.execCommand("HiliteColor", false, color);
                              sel.collapseToEnd();
                          }
                          document.designMode = "off";
                      } else if (document.body.createTextRange) {
                          var textRange = document.body.createTextRange();
                          while (textRange.findText(text)) {
                              textRange.execCommand("BackColor", false, color);
                              textRange.collapse(false);
                          }
                      }
                  }

                  <input type="text" id="search">
                  <input type="hidden" id="hid_search">
                  <input type="button" id="button" onmousedown="doSearch(document.getElementById('search').value)" value="Find">
                  
                  <div id="content">
                      <p>Here is some searchable text with some lápices in it, and more lápices, and some <b>for<i>mat</i>t</b>ing</p>
                  </div> 

                  这篇关于HTML 中的全文搜索忽略标签/&amp;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果 下一篇:放&lt;span/&gt;不好吗?&lt;option/&gt; 中的标签标签,仅用于

                  相关文章

                    <bdo id='H80Dm'></bdo><ul id='H80Dm'></ul>

                  <small id='H80Dm'></small><noframes id='H80Dm'>

                • <i id='H80Dm'><tr id='H80Dm'><dt id='H80Dm'><q id='H80Dm'><span id='H80Dm'><b id='H80Dm'><form id='H80Dm'><ins id='H80Dm'></ins><ul id='H80Dm'></ul><sub id='H80Dm'></sub></form><legend id='H80Dm'></legend><bdo id='H80Dm'><pre id='H80Dm'><center id='H80Dm'></center></pre></bdo></b><th id='H80Dm'></th></span></q></dt></tr></i><div id='H80Dm'><tfoot id='H80Dm'></tfoot><dl id='H80Dm'><fieldset id='H80Dm'></fieldset></dl></div>
                  <tfoot id='H80Dm'></tfoot>

                  <legend id='H80Dm'><style id='H80Dm'><dir id='H80Dm'><q id='H80Dm'></q></dir></style></legend>