//强制给数字补全小数点 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);
时间: 2024-10-07 00:55:11