本文介绍了如何改变基于下拉上下文的jQuery输入掩码掩码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 目前我正在使用 jQuery输入框来达到以下效果: 这对US& amp;相当简单;加拿大电话号码格式使用类似于: $(#user_phone)。inputmask(mask,{mask :(999)999-9999}); 然而,我想要根据国家代码下拉菜单来更改此格式上下文,当它是英国的时候,它会使用另一个面具等等。我如何实现这个功能,以便面具根据js / jQuery中的下拉菜单改变上下文? 这里有一个现在的工作源示例: http://jsfiddle.net/j9aNh/1/ 更新:好的,我认为我现在已经能够令人满意地工作了,并且希望得到任何有关干扰的建议: http://jsfiddle.net/j9aNh/3/ 解决方案我不知道你是否在寻找什么,但它可以像我想的那样简单。 var country = $(this).val()//或者如果你想获得文本,你可以使用var合作untry = $(this).text() var maskuse; if(country =='USA') { maskuse =(999)999-9999; $ b if(country =='Canada') { maskuse =(999)999-9999; $ b ///并很快改变了一个国家的掩码 $(#user_phone)。inputmask(mask,{mask: maskuse}); }); I'm presently using jQuery inputmask for the following effect:It's fairly simple for US & Canada phone number formatting using something like:$("#user_phone").inputmask("mask", { "mask": "(999) 999-9999" });I would, however, like to change this formatting context based on the "Country code" dropdown such that when it is United Kingdom, it uses another mask, etc. How would I implement this such that the mask will change context based on dropdown in js/jQuery?Here's an example of the working source as it is now: http://jsfiddle.net/j9aNh/1/UPDATE: Okay, I think I've got it working satisfactorily now and would appreciate any advice in terms of drying this up properly: http://jsfiddle.net/j9aNh/3/ 解决方案 I do not know if that what you are looking for but it could be as simple as that I think.$('select').change(function() {var country=$(this).val() //or if you want to get text you may use var country=$(this).text() var maskuse;if(country=='USA'){maskuse="(999) 999-9999";}if(country=='Canada'){maskuse="(999) 999-9999";}/// and soon changing mask for a country $("#user_phone").inputmask("mask", { "mask": maskuse });}); 这篇关于如何改变基于下拉上下文的jQuery输入掩码掩码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 12:28