学习要点:
1.问题所在
2.设置代码
注册验证功能,顾名思义就是验证表单中每个字段的合法性,如果全部合法才可以提交
表单。
一.问题所在
QQ截图20190517094351.png二.设置代码
JS 代码
var year = $('form').form('year');
var month = $('form').form('month');
var day = $('form').form('day');
//年
for (var i = 1950; i <= 2013; i ++) {
year.first().add(new Option(i, i), undefined);
}
//月
for (var i = 1; i <=12; i ++) {
month.first().add(new Option(i, i), undefined);
}
//日
var day30 = [4, 6, 9 ,11];
var day31 = [1, 3, 5, 7, 8, 10, 12];
year.bind('change', select_day);
month.bind('change', select_day);
function select_day() {
if (month.value() != 0 && year.value() != 0) {
var cur_day = 0;
if (inArray(day31, parseInt(month.value()))) {
cur_day = 31;
} else if (inArray(day30, parseInt(month.value()))) {
cur_day = 30;
} else {
if ((parseInt(year.value()) % 4 == 0 && parseInt(year.value()) % 100 != 0)
|| parseInt(year.value()) % 400 == 0) {
cur_day = 29;
} else {
cur_day = 28;
}
}
day.first().options.length = 1;
for (var i = 1; i <= cur_day; i ++) {
day.first().add(new Option(i, i), undefined);
}
} else {
day.first().options.length = 1;
}
}
//判断某一值是否存在某个数组里
function inArray(array, value) {
for (var i in array) {
if (array[i] == value) return true;
}
return false;
}
网友评论