如何绑定国家/地区更改国际电话输入

huk*_*750 2 javascript jquery onchange intl-tel-input

我使用国家/地区代码插件名称intlTelInput.js \n(这是我的演示页面)\n在国家/地区选择更改时我想清空手机(输入字段)的页面

\n\n
<div class="demo">\n    <h3>Demo</h3>\n    <div class="iti iti--allow-dropdown">\n        <div class="iti__flag-container">\n            <div class="iti__selected-flag" role="combobox" aria-owns="country-listbox" tabindex="0"\n                title="Algeria (&#8235;\xd8\xa7\xd9\x84\xd8\xac\xd8\xb2\xd8\xa7\xd8\xa6\xd8\xb1&#8236;&lrm;): +213">\n                <div class="iti__flag iti__dz"></div>\n                <div class="iti__arrow"></div>\n            </div>\n        </div><input type="tel" id="phone" class="form-control" autocomplete="off" data-intl-tel-input-id="0"\n            placeholder="0551 23 45 67">\n    </div>\n</div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我试过:

\n\n
$(".iti__selected-flag").bind(\'change\', function(event) {\n         $(\'#phone\').val(\'\')\n      });\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n下面的代码将使电话字段值清空(单击时,但我希望在选择另一个国家/地区项目完成后将其清空)

\n\n
$(function(){\n      $("#phone").bind(\'change\', function(event) {\n         $(\'#phone\').val(\'\')\n      });\n    })\n
Run Code Online (Sandbox Code Playgroud)\n\n

但它不起作用

\n

Ped*_*ram 6

有一种本地方法可以绑定国家/地区更改intl-tel-input

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

input.on("countrychange", function() {
  input.val('')
});
Run Code Online (Sandbox Code Playgroud)