//強制給數字補全小數點 function toDecimal2(x) { var f = parseFloat(x); if(isNaN(f)) { return false; } var f = Math.round(x * 100) / 100; var s = f.toString(); var rs = s.indexOf('.'); if(rs < 0) { rs = s.length; s += '.'; } while(s.length <= rs + 2) { s += '0'; } return s; }
//查詢全部列表並追加到div中 var list = data.doctorList; var html = ''; for(var i = 0; i < list.length; i++) { var imgUrl = list[i].doctorImg; var docName = list[i].doctorName; var docDev = list[i].doctorDevlement; var hosName = list[i].hospitalName; console.log("圖片地址" + imgUrl); console.log("醫生名稱" + docName); console.log("科室" + docDev); console.log("醫院名稱" + hosName); html += '<div class="weui-jiaj-panel">' + '<a href="department/change_doctor_info.html" class="weui-jiaj-a-color" data-id="doctorInfo">' + '<div class="weui-media-box weui-media-box_appmsg">' + '<div class="weui-media-box__hd">' + '<img class="weui-media-box__thumb" src="' + imgUrl + '" />' + '</div>' + '<div class="weui-media-box__bd">' + '<h4 class="weui-media-box__title">' + docName + '</h4>' + '<p class="weui-media-box__desc">' + docDev + '</p>' + '<p class="weui-media-box__desc">' + hosName + '</p>' + '</div>' + '<div class="weui_jia_cell_ft"></div>' + '</div>' + '</a>' + '</div>'; } $('#tab1').append(html);
//點擊button,獲取每一個按鈕的名稱 $('.depart-btn').click(function(){ var value = $(this).attr('name'); //$(this)表示獲取當前被點擊元素的name值 console.log("當前button的名稱爲" + value); })
//獲取URL中參數的方法 function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r = window.location.search.substr(1).match(reg); if (r != null) { //return unescape(r[2]); 註釋:ECMAScript v3 已從標準中刪除了 unescape() 函數,並反對使用它,所以應該用 decodeURI() 和 decodeURIComponent() 取而代之。若是繼續使用unescape函數,則在獲取中文參數時會致使獲致 到的參數亂碼,所以下面是改 return decodeURI(r[2]); } return null; } //若是url中的參數是toutiaoForwardId與shareShortCode //下面的方法是調用getQueryString獲取Name //http://127.0.0.1:8020/wx/admin/department/change_doctor_info.html?toutiaoForwardId=121f1a var toutiaoForwardId = getQueryString('toutiaoForwardId'); var shareShortCode = getQueryString('shareShortCode');
//點擊按鈕,獲取input的值,並經過url傳遞給下一個頁面 $('#saveHospitalName').click(function(){ var hospitalName = $('#hospitalName').val(); console.log("醫院名稱" + hospitalName); window.location.href = "/wx/admin/department/change_doctor_info.html?hospitalName=" + hospitalName; });
//彈框,點擊保存按鈕,把彈框中的數據保存在當前頁面 $('#saveDoctorName').click(function(){ var doctorName = $('#doctorName').val(); //input的值 $('#doctorNameShow').html(doctorName); //當前頁面值的保存位置 })
//在一個div中動態添加BTN var doctorTitelListData = doctorTitel.doctorTitelList; var $titleHtml = ''; for(var a = 0; a < doctorTitelListData.length; a++){ var titleName = doctorTitelListData[a].doctorTitelName; $titleHtml += '<button class="weui-btn weui-btn_mini weui-btn_default title-btn"' + 'name=' + titleName + '>' + titleName + '</button>'; } $('#doctorTitleBox').append($titleHtml);