No-refreshing ajax comments and refreshing ajax comments

Source: Internet
Author: User

No-refreshing ajax comments and refreshing ajax comments

This is the message board interface. When you click to submit a message, it is automatically submitted to my message.

If the message content is blank or the gray content is left blank, enter the message content. When the user fills in the information, the number of words of the current message will be displayed in the lower right corner.

Below is the javascript code

// Remove the left and right corner brackets and use the string after removing the space to replace the 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 ("message content not filled"); return false;} replaceBrackets ("txtMessage"); return true ;}); $ ("# txtMessage "). focus (function () {if ($ ("# txtMessage "). val () = "no message filled") {document. getElementById ("txtMessage "). style. color = "#000000"; $ ("# txtMessage "). val ("") ;}}); function txtanum (id, Name) // count the input words of txta {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 () = "no message filled" | $. trim ($ ("# txtMessage "). val () = "") {alert ("Enter the message content! "); 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 ("no message content filled") ;}}); 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 + "'> View </a>"); html. push ("</td>"); html. push ("</tr>"); html = html. join (''); table. append (html );}});

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.