Sometimes in order to generate the page with js in the project, some common times and drop-downs in the page. . . . . . Sometimes it can't be achieved through jsp page expressions, but it can be achieved through js global variables.
Public js file: publicAppWeb.js
/** * Get Time * @param days The number of days to add at the current time * Pass 0 for the current day, 1 for tomorrow... */ function formatDate(days){ var newDate = new Date(); newDate.setDate(newDate.getDate()+days); var newMonth = newDate.getMonth() + 1; var newDay = newDate.getDate(); if (newMonth >= 1 && newMonth <= 9) { newMonth = "0" + newMonth; } if (newDay >= 0 && newDay <= 9) { newDay = "0" + newDay; } var backDate = newDate.getFullYear() + "-" + newMonth + "-" + newDay; return backDate; } /** * Query dictionary table value according to table, column, desc */ function queryDictionaryValue(table,column,desc){ var value =""; $.ajax({ type: "POST", async:false, url:$.getUrl() + "/dictionary/queryDictionarySingle", data:{ table:table, column:column, desc: desc }, success: function(msg){ value=msg.value; } }); return value; }
When using, import the publicAppWeb.js file on the queryBlacklist.jsp page, and then use the primary key defined before publicAppWeb.js in queryBlacklist.js;
use code
//Set the drop-down list of name="controlKey" under from under id="updateBlackForm", and the item whose value is 'xxxx' is selected by default $("#updateBlackForm select[name='controlKey']").val(queryDictionaryValue('t_blacklist','Fcontrol_key',ret.controlKey)); $("#updateBlackForm select[name='blacklistStatus']").val(queryDictionaryValue('t_blacklist','Fblacklist_status',ret.blacklistStatus)); //Set the default value of the text box with name="startTime_1" under from under id="commentForm" (the default value here is time) $("#commentForm input[name='startTime_1']").val(formatDate(0)), $("#commentForm input[name='endTime_1']").val(formatDate(7)),