这里我们使用 Jquery 载入数据。
在 HTML 中定义:<p class="phone">6036918972</p>
格式化美国电话号码的代码如下: $(".phone").text(function (i, text) {
text = text.replace(/(\d\d\d)(\d\d\d)(\d\d\d\d)/, "$1-$2-$3");
return text;
});
运行结果为:603-691-8972
单击下面的链接可以自己尝试下:http://jsfiddle.net/yuchenghu/uhQa5/