[英]how to bind country change intl tel input
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我在页面中使用国家代码插件名称intlTelInput.js (这个我的演示页面)我想在国家选择更改时清空电话(输入文件)
<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 (‫الجزائر‬‎): +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但它不起作用
There is a native way to bind country change intl-tel-input :有一种本地方法可以绑定国家/地区更改intl-tel-input :
var input = $("#phone");
input.intlTelInput();
input.on("countrychange", function() {
input.val('')
});
var input = document.querySelector("#phone1");
window.intlTelInput(input, {
initialCountry: "In", //change according to your own country.
utilsScript: "assets/js/utils.js",
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.