验证中...
Languages: JavaScript
Categories: 其他
Latest update 2019-08-14 11:29
gistfile1.txt
Raw Copy
/**
* 生成从until到当前数字的数组
* @param {*} num 数字
* @param {*} el 挂载的元素
* @param {*} until 到什么时候结束
* @param {*} direction 方向false 倒序, true正序
*/
let year = new Date().getFullYear()
YYmmdd(year, '#new-account-form-year', year - 150, false)
YYmmdd(12, '#new-account-form-month', 0)
YYmmdd(31, '#new-account-form-day', 0)
function YYmmdd(num, el, until, direction = true) {
let html = ''
for (let i = 0; i < num; i++) {
if (i >= num - until) {
break
} else {
if (direction) {
html += '<option value=' + (i + 1) + '>' + add0(i + 1) + '</option>'
} else {
html += '<option value=' + (num - i) + '>' + add0(num - i) + '</option>'
}
}
}
$(el).append(html)
}
/**
* 数字小于0时前面加0
* @param {*} num Number
* @returns
*/
function add0(num) {
return num < 10 ? ('0' + num) : num
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search