代码比较简单,随便写写
/** * a连接快速选择日期函数 */ function timeChooseSimple(key, me) { //today,tomorrow,thisWeek,nextWeek var me = $(me); var input = me.parent().prev().prev().find('input'); if (key == 'today') { var year = new Date().getFullYear(); var month = new Date().getMonth() + 1 <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1; var strDate = new Date().getDate() <= 9 ? '0' + new Date().getDate() : new Date().getDate(); var time = year + '-' + month + '-' + strDate; } else if (key == 'tomorrow') { var tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate() + 1); var year = tomorrow.getFullYear(); var month = tomorrow.getMonth() + 1 <= 9 ? '0' + (tomorrow.getMonth() + 1) : tomorrow.getMonth() + 1; var strDate = tomorrow.getDate() <= 9 ? '0' + tomorrow.getDate() : tomorrow.getDate(); var time = year + '-' + month + '-' + strDate; } else if (key == 'thisWeek') { var day = new Date().getDay(); //0=周日, var minus = 5 - day; var thisWeek = new Date(); thisWeek.setDate(thisWeek.getDate() + minus); var year = thisWeek.getFullYear(); var month = thisWeek.getMonth() + 1 <= 9 ? '0' + (thisWeek.getMonth() + 1) : thisWeek.getMonth() + 1; var strDate = thisWeek.getDate() <= 9 ? '0' + thisWeek.getDate() : thisWeek.getDate(); var time = year + '-' + month + '-' + strDate; } else if (key == 'nextWeek') { var day = new Date().getDay(); //0=周日, var minus = 5 - day; var nextWeek = new Date(); nextWeek.setDate(nextWeek.getDate() + minus + 7); var year = nextWeek.getFullYear(); var month = nextWeek.getMonth() + 1 <= 9 ? '0' + (nextWeek.getMonth() + 1) : nextWeek.getMonth() + 1; var strDate = nextWeek.getDate() <= 9 ? '0' + nextWeek.getDate() : nextWeek.getDate(); var time = year + '-' + month + '-' + strDate; } return time; }
调用代码
以上