当用户在字段中输入CookingDB
时,我将此Recipe
CookingTime
的功能设置为mask
。我使用了date
,奇怪的是当date
与字段无关时,这可以按预期工作。
注意 - 我在IE8中遇到此问题,但在IE11,Chrome等中工作正常,
问题示例:在jquery-ui-datepicker
字段中键入121,它应该用datepicker
替换它,但它会放置额外的字符,如date
。任何人都可以让我知道造成这个问题的原因:
12/1
更新:
刚放置调试器并注意到
12/11
在上面的行中function maskDate(element) {
var chr = window.event.keyCode
var str = document.getElementById(element).value
var lastindex = str.length - 1
var lastchr = str.charAt(lastindex)
if (chr < 48 || chr > 57) {
if (str.length == 1 && (chr == 45 || chr == 47)) {
document.getElementById(element).value = "0" + str + "/";
return false;
}
if (str.length == 4 && (chr == 45 || chr == 47)) {
document.getElementById(element).value = str.substr(0, lastindex) + "0" + lastchr + "/";
return false;
}
if (chr == 47 && (str.length == 2 || str.length == 5)) return true;
else {
if (chr == 45 && (str.length == 2 || str.length == 5))
document.getElementById(element).value = str + "/";
return false;
}
}
else {
if (str.length == 2 || str.length == 5) {
document.getElementById(element).value = str + "/" + String.fromCharCode(chr);
return false;
}
if (str.length > 9) return false;
return true;
}
}
的值正在设置正确,但是我没有得到额外值设置的位置,因为控件在返回false后传递给document.getElementById(element).value = str + "/" + String.fromCharCode(chr);
,这使得复杂化了解确切的流量然后!