how to bind country change intl tel input

筅森魡賤 提交于 2021-01-01 08:15:33

问题


I using country code plugin name intlTelInput.js (this I demo page) in the page I want to empty the phone (input filed) when country select change

<div class="demo">
    <h3>Demo</h3>
    <div class="iti iti--allow-dropdown">
        <div class="iti__flag-container">
            <div class="iti__selected-flag" role="combobox" aria-owns="country-listbox" tabindex="0"
                title="Algeria (&#8235;الجزائر&#8236;&lrm;): +213">
                <div class="iti__flag iti__dz"></div>
                <div class="iti__arrow"></div>
            </div>
        </div><input type="tel" id="phone" class="form-control" autocomplete="off" data-intl-tel-input-id="0"
            placeholder="0551 23 45 67">
    </div>
</div>

I tried:

$(".iti__selected-flag").bind('change', function(event) {
         $('#phone').val('')
      });

And below code will make phone filed value empty (when click , but I want it empty when after select another country item done)

$(function(){
      $("#phone").bind('change', function(event) {
         $('#phone').val('')
      });
    })

But it not working


回答1:


There is a native way to bind country change intl-tel-input:

var input = $("#phone");
input.intlTelInput();

input.on("countrychange", function() {
  input.val('')
});


来源:https://stackoverflow.com/questions/60034134/how-to-bind-country-change-intl-tel-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!