javascript jquery datepicker 和 jquery 掩码不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25136650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery datepicker and jquery mask not working
提问by Yuliam Chandra
I have this piece of code that uses jquery datepickerand jquery masked input.
我有一段使用jquery datepicker和jquery masked input的代码。
jQuery(function($) {
$(document).on('click', '#date', function () {
var me = $("#date");
me.datepicker({
showOn: 'focus',
altFormat: "mm/dd/yy",
dateFormat: "mm/dd/yy",
minDate: '12/12/2000',
maxDate: '12/12/2020'
}).focus();
me.mask('99/99/9999');
}).on('select', '#date', function () {
var me = $("#date");
me.mask('99/99/9999');
});
});
The code uses jquery onbecause the input element in the application is dynamically added into the page. And the masked input is also registered from select
event because user can come to the input by pressing tab from previous input.
代码使用jquery on是因为应用程序中的输入元素是动态添加到页面中的。并且屏蔽输入也从select
事件注册,因为用户可以通过从先前输入中按 Tab 键来进入输入。
It doesn't work on Firefox 31
, but it works fine on Chrome 36
and IE 11
.
When the input field is empty, user should be able to type anything (based on masked filter) in the input element.
它不适用于Firefox 31
,但它适用于Chrome 36
和IE 11
。当输入字段为空时,用户应该能够在输入元素中输入任何内容(基于屏蔽过滤器)。
Kindly suggest me what's wrong with the code.
请建议我代码有什么问题。
采纳答案by Yuliam Chandra
Just fixed it by changing the select
into focus
, I can't remember why I used select
in the first place.
只需通过改变固定它select
到focus
,我不记得为什么我用select
摆在首位。
jQuery(function($) {
$(document).on('click', '#date', function () {
var me = $("#date");
me.datepicker({
showOn: 'focus',
altFormat: "mm/dd/yy",
dateFormat: "mm/dd/yy",
minDate: '12/12/2000',
maxDate: '12/12/2020'
}).focus();
}).on('focus', '#date', function () {
var me = $("#date");
me.mask('99/99/9999');
});
});