国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > AJAX > 正文

ajax無刷新評(píng)論功能

2024-09-01 08:27:29
字體:
供稿:網(wǎng)友

這是留言板的界面,當(dāng)用戶點(diǎn)擊提交留言的時(shí)候,自動(dòng)提交到我的留言下面

留言內(nèi)容中為空,或者為灰色的“沒有填寫留言內(nèi)容”都會(huì)彈出 請(qǐng)?zhí)顚懥粞詢?nèi)容,當(dāng)用戶填寫信息的會(huì)在右下角顯示當(dāng)前留言的字?jǐn)?shù)。

下面是javascript的代碼

//去掉左右尖括號(hào) 并用去掉空格后的字符串替代顯示 function replaceBrackets(id) {   var inputValue = $("#" + id).val();   while (inputValue.indexOf("<") != -1) {     inputValue = inputValue.replace("<", "[");   }   while (inputValue.indexOf(">") != -1) {     inputValue = inputValue.replace(">", "]");   }   while (inputValue.indexOf("&") != -1) {     inputValue = inputValue.replace("&", " ");   }   $("#" + id).val(inputValue); }  function replaceChar(name, char) {   var inputValue = $("#" + name).val();   while (inputValue.indexOf(char) != -1) {     inputValue = inputValue.replace(char, "");   }   return inputValue; }  $("#txtMessage").blur(function () {   $("#txtMessage").val(replaceChar("txtMessage", "<!--"));   if ($("#txtMessage").val() == "") {     document.getElementById("txtMessage").style.color = "#8C8C8C";     $("#txtMessage").val("沒有填寫留言內(nèi)容");     return false;   }   replaceBrackets("txtMessage");   return true; });  $("#txtMessage").focus(function () {   if ($("#txtMessage").val() == "沒有填寫留言內(nèi)容") {     document.getElementById("txtMessage").style.color = "#000000";     $("#txtMessage").val("");   } });  function txtanum(id, name)  //統(tǒng)計(jì)txta的輸入字?jǐn)?shù) {   var maxl = 151;   var num = 150;   var content = $("#" + id).val();   content.slice(0, maxl);   var nowlength = content.length;   if (nowlength >= 0) {     if (nowlength < num)       $("#" + name).text(nowlength);     else       $("#" + name).text(num);   } else     $("#" + id).val(content.substring(0, maxl - 1));    if (nowlength == 0)     $("#" + name).text(0);    if (nowlength > num)     $("#" + id).val(content.substring(0, num)); }   var isSubmit = false; $('#subMessage').click(function () {    if (isSubmit) {     return;   }   isSubmit = true;   if ($("#txtMessage").val() == "沒有填寫留言內(nèi)容" || $.trim($("#txtMessage").val()) == "") {     alert("請(qǐng)輸入留言內(nèi)容!");     isSubmit = false;     return;   }   $.ajax({     type: "POST",     url: app_param.path_context+"/user/member/msgboard/save",     data: { "context": ($("#txtMessage").val()) },     error: function () {       isSubmit = false;     },     success: function (data) {       if (data) {         addRow(data);         isSubmit=false;        $('#zanwu').hide();         document.getElementById("txtMessage").style.color = "#8C8C8C";     $("#txtMessage").val("沒有填寫留言內(nèi)容");       }      }   });   function addRow(messageboard) {     var table = $("#tblmsg");     var html = [];     html.push("<tr>");     html.push("<td class='m_time'>");     html.push(messageboard.createDate);     html.push("</td>");     html.push("<td>");     html.push(messageboard.context);     html.push("</td>");     html.push("<td style='border-right: 0;' class='m_order_procz'>");     html.push("<a class='xxx' href='messagereply/"+messageboard.id+"'>查看</a>");     html.push("</td>");     html.push("</tr>");     html = html.join('');     table.append(html);   }  });             
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 丰顺县| 尼木县| 屏南县| 阿尔山市| 鄢陵县| 中江县| 郯城县| 荣成市| 金坛市| 巧家县| 方城县| 芒康县| 河源市| 西峡县| 东港市| 维西| 道真| 海南省| 伊川县| 凤城市| 鹤壁市| 乌拉特中旗| 昌乐县| 丹凤县| 鸡东县| 汶川县| 探索| 昌邑市| 呼玛县| 永嘉县| 光山县| 资兴市| 杭锦后旗| 盐城市| 花莲市| 平谷区| 临朐县| 蓬安县| 南郑县| 丹阳市| 通河县|