问题描述
有一个JavaScript库可以识别网页中的电话号码吗?就像在他们的Firefox插件上做的那样。或者你知道怎么做的方法吗?网站或任何教程,做同样的将是非常有用的。
您的答复非常感激。
最好,
其他人可能有更好的方式来做到这一点,但这似乎给你一个链接每个电话号码。
我刚刚使用了简单的正则表达式,因此您可能需要替换 Adam 提供的那个。
$(document).ready(function(){
$('*','body')。 ){
$(this).html($(this).html()。replace(/(\d\d\d- \\\\\\\\\\\\\\\\\ \\ d \\ d)/ g,'< a href =#> $ 1< / a>));
});
}) ;
希望有帮助。
编辑:
这个版本可能会更好,或者更好。
$ b $
$(document).ready(function(){
$('body')。html($('body') .html()。replace(/(\d\d\d- \d\d\d- \d\d\d\d)/ g,< a href =#> $ 1< / a>));
});
我不知道是否有任何的陷阱,但似乎与一个相当简单的页面工作。
Is there a javascript library the can recognize phone numbers in a web page? Just like what skype did on their firefox plugin.
Or do you know a way on how to do it? Websites or any tutorial that do the same would be very helpful.
Your reply is greatly appreciated.
Best,
Someone else may have a better way of doing this, but this seems to give you a link around each phone number.
I just used my simple regular expression, so you may want to substitute the one that Adam provided.
$(document).ready(function () {
$('*','body').each(function() {
$(this).html( $(this).html().replace(/(\d\d\d-\d\d\d-\d\d\d\d)/g,'<a href="#">$1</a>') );
});
});
Hope it helps.
EDIT:
It may work as well, or better, with this version.
$(document).ready(function () {
$('body').html( $('body').html().replace(/(\d\d\d-\d\d\d-\d\d\d\d)/g,'<a href="#">$1</a>') );
});
I don't know if there are any pitfalls, but seems to work with a fairly simple page.
这篇关于电话号码识别在Javascript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!