' + '
' + (res.data[i].nickname != null ? res.data[i].nickname : res.data[i].username) + '' + '' + res.data[i].create_date + '' + '
' + '
' + res.data[i].content + '
' + '
' + ''; } $(".more").before(com); page++; $('#page_number').html( res.last_page - res.current_page) $(".con_wrap").last().addClass("_nobor"); } $("#comments_total").html(res.total); }, }); } $('.submit').click( function() { var con = $('.comment_con')[0].value if (!con.trim()) { toast('回答内容不能为空'); return; } $.ajax({ type : "POST", //用POST方式传输 url : "/qa_comments/add", //请求接口地址 data : { qa_id : "30431", content : con.trim(), }, error : function(XMLHttpRequest, textStatus, errorThrown) { console .log("consultingAppointment接口 请求失败", XMLHttpRequest, textStatus, errorThrown); }, success : function(res) { // 成功回调函数 toast(res.msg); if (res.code != 1) { return false; } location.reload(); }, }); }) // 回答 var length = $('.length span') $('.comment_con').bind('input propertychange', function(e) { if (e.target.textLength >= 200) { length.text(200) e.target.value = e.target.value.slice(0, 200) } else { length.text(e.target.textLength) } }) function toast(msg, duration) { duration = duration || 2000 var div = document.createElement("div"); $(div).css({ position : "fixed", top : "50%", left : "50%", transform : "translate(-50%,-50%)", background : "rgba(51,55,71,0.80)", width : "max-content", borderRadius : "4px", padding : "16px", fontFamily : "PingFangSC-Medium", fontSize : "16px", color : "#FFFFFF", letterSpacing : 0, textAlign : " center", zIndex : "10000", maxWidth : "480px", }); div.innerHTML = msg; $("body").append(div); setTimeout(function() { $(div).remove(); }, duration); } });