【发布时间】:2017-01-16 06:50:12
【问题描述】:
我在 asp.net webform 网站上的电话和移动领域使用intlTelInput。
目前我将它用作基本插件,如example 所示
var input = $("#ContentPlaceHolder1_txtPhone"), output = $("#output");
var country = $("#ContentPlaceHolder1_ddCountry");
input.intlTelInput({
preferredCountries: ['ae'],
autoHideDialCode: true,
nationalMode: false,
utilsScript: "../../Scripts/phone/js/utils.js" // just for formatting/placeholders etc
});
现在我正在尝试将其与“国家/地区”下拉菜单同步,以便当用户选择国家/地区时,它会自动选择网络表单上的电话字段和移动字段,并在电话字段中选择国家。
我尝试使用此示例,但它无法正常工作,要么破坏插件,要么无法正常工作
http://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/country-sync.html
我尝试过的代码
var countryData = $.fn.intlTelInput.getCountryData(),
telInput = $("#ContentPlaceHolder1_txtPhone"),
addressDropdown = $("#ContentPlaceHolder1_ddCountry");
// set it's initial value
//var initialCountry = telInput.intlTelInput("getSelectedCountryData").iso2;
//addressDropdown.val(initialCountry);
// listen to the telephone input for changes
telInput.on("countrychange", function (e, countryData) {
addressDropdown.val(countryData.iso2);
});
// listen to the address dropdown for changes
addressDropdown.change(function () {
telInput.intlTelInput("setCountry", $(this).val());
});
我在 codepen http://codepen.io/anon/pen/wgzppg 上有地方代码。
我不确定我在哪里做错了。我尝试了一些没有任何运气的东西。
我从数据库表而不是插件中提取国家下拉列表的数据,因此可能会在某处引起问题。但国家代码也匹配。
【问题讨论】:
标签: javascript jquery asp.net intl-tel-input