ajax無刷新評論功能
這是留言板的界面,當(dāng)用戶點擊提交留言的時候,自動提交到我的留言下面
留言內(nèi)容中為空,或者為灰色的“沒有填寫留言內(nèi)容”都會彈出 請?zhí)顚懥粞詢?nèi)容,當(dāng)用戶填寫信息的會在右下角顯示當(dāng)前留言的字?jǐn)?shù)。
下面是javascript的代碼
//去掉左右尖括號 并用去掉空格后的字符串替代顯示 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)計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("請輸入留言內(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); } });
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ajax提交到servelt獲取參數(shù)有亂碼的解決方法
這篇文章主要介紹了ajax提交到servelt獲取參數(shù)有亂碼的解決方法,需要的朋友可以參考下2014-02-02關(guān)于Ajax技術(shù)原理的3點總結(jié)
這篇文章主要介紹了關(guān)于Ajax技術(shù)原理的3點總結(jié),需要的朋友可以參考下2014-12-12Ajax實現(xiàn)動態(tài)加載數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了Ajax動態(tài)加載數(shù)據(jù)的小例子,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05Ajax請求成功后return無法接收到返回值的問題及解決方案
項目中需要頻繁的用到ajax請求,所以就想用一個方法將整個請求封裝起來,直接調(diào)用方法傳遞參數(shù),然后返回請求結(jié)果就可以了,這篇文章主要介紹了ajax請求成功后return無法接收到返回值,需要的朋友可以參考下2023-10-10Ajax Control Toolkit 34個服務(wù)器端控件
Ajax Control Toolkit 34個服務(wù)器端控件,想要學(xué)習(xí)ajax的朋友可以參考下。2009-09-09