包裹< a>使用jquery标记电话号码 [英] Wrap <a> tag around phone number using jquery

查看:91
本文介绍了包裹< a>使用jquery标记电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AJAX加载页面,并希望使用Jquery在加载的页面上搜索电话号码(格式为555.555.5555)并使用电话链接进行包装:

I'm loading a page with AJAX and would like to use Jquery to search for phone numbers (whose format is 555.555.5555) on the loaded page and wrap them with tel links:

<a href="tel:phone-number-here"> </a>

我知道我需要完成的部分(我认为):Regex和.wrap()。我只是不确定如何将它们与我所拥有的代码拼凑在一起。我也不确定如何让Jquery保留找到的数字并将它们插入tel链接中。我是否必须使用每个和$(this)变量?

I know the parts I need to accomplish this (I think): Regex and .wrap(). I'm just not sure how to piece them together with the code I've got. I'm also not sure how to get Jquery to retain found numbers and insert them inside the tel links. Would I have to use each and $(this) with variables?

这是我发现的用于识别7-10位数字的正则表达式。如果我们的网站在将来停止使用期限,我想将其保留给各种分隔符:

Here's the regex I found for identifying 7 - 10 digit numbers. I want to leave it open to various delimiters in case our site stops using periods in the future:

^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$

这是我用来加载每个页面的代码:

And here's the code I'm using to load each page:

 $(".services").click(function(){  
    var loadUrl = "http://www.example.com";      
    $("#content").html(ajax_load).load(loadUrl + " #content");  
 });

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

这个问题将告诉你如何获得页面上具有特定字符串的所有元素。你也可以使用正则表达式。然后你可以使用正则表达式对所有找到的元素进行字符串替换。

This question will show you how to get all the elements on a page with a certain string. You could probably use a regex as well. Then you could do string replacement using your regex on all the found elements.

这篇关于包裹&lt; a&gt;使用jquery标记电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆