Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅将类添加到HTML页面中的数字,链接除外_Javascript_Jquery_Html - Fatal编程技术网

Javascript 仅将类添加到HTML页面中的数字,链接除外

Javascript 仅将类添加到HTML页面中的数字,链接除外,javascript,jquery,html,Javascript,Jquery,Html,我在Joomla中尝试了这个脚本,为每个数字添加了一个类,这样我就可以用CSS格式化它们: <script> (function($) { $(function() { $('h1,h2,h3,h4,h5,h6,p,strong,i,em,b,span,sup,sub').each(function() { var el = $(this), html = el.html(); html = html.r

我在Joomla中尝试了这个脚本,为每个数字添加了一个类,这样我就可以用CSS格式化它们:

<script>
  (function($) {
    $(function() {
      $('h1,h2,h3,h4,h5,h6,p,strong,i,em,b,span,sup,sub').each(function() {
        var el = $(this),
            html = el.html();
        html = html.replace(/(\d)/gi, "<span class='number'>$1</span>");
        el.html(html);
      });
    });
  })(jQuery);
</script>
在这种情况下,它会:

www.miosito.it/index.php&articleid=<span class="number">2</span>
www.miosito.it/index.php&articleid=2

因此,链接已断开。如何编辑脚本来修复它?

一个更安全的策略是只在文本节点上运行正则表达式,而不是在原始html上运行正则表达式,正如一个更安全的策略是只在文本节点上运行正则表达式,而不是在原始html上运行正则表达式,如
www.miosito.it/index.php&articleid=<span class="number">2</span>