簡體   English   中英

從 jQuery 國際電話輸入插件獲取帶有國家代碼的完整號碼

[英]getting fullnumber with countrycode from jQuery International Telephone Input Plugin

我正在使用 jQuery 國際電話輸入插件來獲取國家代碼和電話號碼。 html代碼

<div class="form-group">
<input type="tel"  placeholder="Phone*" id="telephone" name="telephone" class="form-control">
</div>

插件的初始化

jQuery("#telephone").intlTelInput({
   // options here
   allowDropdown:true,
   autoHideDialCode:true,
   autoPlaceholder:"polite",
   separateDialCode:true,
    customPlaceholder:null

  });

如何使用電話號碼獲取完整的國家代碼。

我無法使用 jQuery 重新創建插件。 但是請看下面的 vanilla JS 示例。 該插件有一個公共方法getNumber() ,您可以通過它獲取號碼。

 var input = document.querySelector("#telephone"); let iti = window.intlTelInput(input, { // options here allowDropdown: true, autoHideDialCode: true, autoPlaceholder: "polite", separateDialCode: true, customPlaceholder: null, utilsScript: "https://raw.githack.com/jackocnr/intl-tel-input/master/build/js/utils.js" }); $(".get-number").on("click", function() { console.log(iti.getNumber()); });
 .get-number { padding: 0.5em 1em; background-color: lightblue; border-radius: 0.2em; display: inline-block; margin: 1em 0; cursor: pointer; }
 <script src="https://raw.githack.com/jackocnr/intl-tel-input/41735773e78c39aad6aaee53a6126215f64aeb57/build/js/intlTelInput.js"></script> <link href="https://raw.githack.com/jackocnr/intl-tel-input/master/build/css/intlTelInput.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="form-group"> <input type="tel" placeholder="Phone*" id="telephone" name="telephone" class="form-control"> </div> <div class='get-number'> Get Number </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM