要求:在頁面添加日期選擇控件,并顯示日期相應(yīng)的標(biāo)題和數(shù)據(jù)。進(jìn)入頁面默認(rèn)2017年01月。
實(shí)現(xiàn):在頁面上添加select控件,js通過調(diào)用id名,實(shí)現(xiàn)日期控件的范圍。
主要問題1:月份控件的1-9月與數(shù)據(jù)庫的兩位數(shù)據(jù)無法對應(yīng)。
【解決:當(dāng)月份為1-9時,在前面添加0
function SetSelect1() {
????????? $(".js-example-basic-single").select2();
????????? var selYear = document.getElementById('selYear');
????????? var selMonth = document.getElementById('selMonth');
????????? setyear("selYear");
????????? setmonth("selMonth");
??????? ? if (new Date().getMonth() >= 1 && new Date().getMonth() <= 9) {
??????????????????? selYear.value = new Date().getFullYear();
??????????????????? selMonth.value = "0".concat(new Date().getMonth());
???????? } else {
?????????????????? selYear.value = new Date().getFullYear();
?????????????????? selMonth.value = new Date().getMonth();
??????? }
}
?】
主要問題2:使用js實(shí)現(xiàn)標(biāo)題動態(tài)變化。
【解決:動態(tài)拼接標(biāo)題語句,并渲染到頁面上。
function SetTitle() {
????????????? $(".page-header").empty();
????????????? $(".page-header").html(
???????????? selYear.value + "年" + selMonth.value + "月" + "醫(yī)聯(lián)常規(guī)統(tǒng)計信息:")
}
】
主要問題3:使用ajax傳入日期選擇參數(shù),并動態(tài)顯示數(shù)據(jù)。當(dāng)數(shù)據(jù)不存在時,提示“暫無數(shù)據(jù)!”
【解決:
function ylcgtjQuery() {
??????? var selYear = $('#selYear').val();
??????? var selMonth = $('#selMonth').val();
??????? SetTitle();
??????? $.ajax({
?????????????????? url : "ylcgtjQuery!getYuzhiset.action",
?????????????????? type : "POST",
?????????????????? data: "selYear="+selYear+"&selMonth="+selMonth,
?????????????????? dataType : "text",
?????????????????? success : function(result) {
????????????????????????? if (result != null) {
???????????????????????? ? ? ? if(result!="nodata"){
???????????????????????? ? ? ? ? ?? ? $("#ylcjtjDesc").empty();
?????????????????????????????????????? var str = result;
??????????????????????????????????????? //返回數(shù)據(jù)中數(shù)字顯示紅色
??????????????????????????????????????? var nums = result.match(/[1-9]\d*\.\d*|0\.\d*[1-9]\d*/g);
??????????????????????????????????????? if(nums!=null){
????????????????????????????????????????????? for ( var i = 0; i < nums.length; i++) {
?????????????????????????????????????????????????????? str = str.replace(nums[i], "" + nums[i]+ "");
?????????????????????????????????????????? ? ? }
???????????????????????????? ? ? ? ?? ? $("#ylcjtjDesc").append(str);
???????????????????????????????????????? }
?????????????????????????????? }else{
???????????????????????????????????????? $("#ylcjtjDesc").empty();
???????????????????????????????????????? var str = "暫無數(shù)據(jù)!";
??????????????????????????????????????? $("#ylcjtjDesc").append(str);
??????????????????????????????? }
???????????????????????? }
????????????????? }
???????? }
);}
】