我在我的网站上使用intlTelInput。如何使用方括号分隔拨号代码。对于前。这个插件的默认输出是+ 1202someNumber,我需要(+1)202someNum吗?

最佳答案

根据此处的文档表单-https://github.com/jackocnr/intl-tel-input-您将需要以下内容:

var intlNumber = $("#phone").intlTelInput("getNumber"); // get full number eg +17024181234
var countryData = $("#phone").intlTelInput("getSelectedCountryData"); // get country data as obj

 var countryCode = countryData.dialCode; // using updated doc, code has been replaced with dialCode
countryCode = "+" + countryCode; // convert 1 to +1

var newNo = intlNumber.replace(countryCode, "(" + coountryCode+ ")" ); // final version

10-06 07:38