PHP implementation of the site top function of the complete front-end code _php tips

Source: Internet
Author: User

Many Web sites support top and step functionality to show users ' satisfaction with the current page content. Below we give the site to use the top, step function of the full foreground implementation code, in order to facilitate the user reference.

The complete front-end code includes HTML, CSS, JS parts of the code. Use the following front-end code, plus a simple implementation of the background code, you can achieve a complete top step function.

Front-End HTML code:

Number of <div id= "vote" data_id= "article unique key" > <span id= "Dig" class= "vote-btn"
  ><span class= "Vote-num" > Top </span></span>
  <span id= "bury" class= "vote-btn" ><span class= "Vote-num" > Step number </span ></span>
</div>

Front-end CSS code:

#vote {/
  * margin:0 auto; */
  text-align:center;
}

. vote-btn {
  margin:0 20px;
  Display:inline-block;
  width:60px;
  height:54px;
  Cursor:pointer;
}

#dig {
  Background:url ("Http://www.jb51.net/static/image/dig.gif");
}

#bury {
  Background:url ("Http://www.jb51.net/static/image/bury.gif");

vote-num {
  display:inline-block;
  font-size:14px;
  margin-top:32px;
  Color:white;
}

Front-end JS code, here The code is based on jquery implementation:

$ ("#vote. Vote-btn"). Bind ("click", Function () {
    var me = $ (this);
    var id = me.parent (). attr ("data_id");
    var type = this.id;
    $.post ("Request Address", {' type ': type, ' ID ': id}, function (data) {
      data = $.trim (data);
      if (data = = ' success ') {   //If the vote is successful
        $num = Me.find (". Vote-num");
        $num. HTML (parseint ($num. HTML ()) + 1); Vote +1
        //Unbind Click event, and restore mouse pointer style
        $ ("#vote. Vote-btn"). Unbind ("click"). CSS ("cursor", "Auto");
        if (type = = ' bury ') {
          alert ("You voted no, please leave a message in the comments so that we can correct it!");          
        }
      else if (data = = ' Done ') {  //If you have already voted
        //Unbind the Click event and restore the mouse pointer
        style $ ("#vote. Vote-btn"). Unbind ("click"). CSS (" Cursor "," Auto ");
        Alert ("You've already voted, you can't vote again!");
      } else{   //voting failed
        alert ("The vote did not succeed because of a system or network problem, it is recommended that you vote again later!");}
    })
  ;

You can change the JS code according to the needs of the backstage.

The general implementation of the background code is: based on the cookie or database data to determine whether the user has voted, if the previous vote, then return to the done; If the voting is successful, return to success; If the vote fails, return an error or other error message.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.