What we are going to accomplish is the evaluation function of the movie Network:
Before we do this function, we need to make the pre-work ready, first let the mouse move to the stars, the left of the stars are yellow stars on the right or gray stars.
We open the template of the content page to see how his code is composed:
We can see it clearly here. He is made up of 20 pictures, so we first bind all the stars to a mouse movement event, onmouseover,
Before writing this function, you must first introduce the jquery library, as follows:
Then bind him with the ID selector as follows:
Then update the next article page template in the background,
Let the mouse on the Stars on the head to see if there is no pop-up OK, if the popup proves that our binding has been successful:
Then continue to modify the template file for the article page:
<script type= "Text/javascript" language= "JavaScript" > $("#rank_pic img"). MouseOver (function(){ //test to see if the bindings are successful //alert (' OK '); //-------------------make the selected single-front star turn yellow go varimgsrc=$ ( This). attr ("src"); IMGSRC=imgsrc.replace ("Rank_3.gif", "Rank_1.gif"); IMGSRC=imgsrc.replace ("Rank_4.gif", "Rank_2.gif"); //new settings to this picture$( This). attr ("src", IMGSRC); //--------------------------------------------- One //Replace all IMG's src on the left of the selected star with yellow Star and change the right side to Gray star, which represents the star to move to.$( This). Prevall (). each (function(){ //iterate through all the stars on the left, modify SRC, this represents a star on the left varimgsrc=$ ( This). attr ("src"); //alert (IMGSRC); //character SubstitutionImgsrc=imgsrc.replace ("Rank_3.gif", "Rank_1.gif"); IMGSRC=imgsrc.replace ("Rank_4.gif", "Rank_2.gif"); //new settings to this picture$( This). attr ("src", IMGSRC); }); //change all pictures on the right to Gray star$( This). Nextall (). each (function(){ varimgsrc=$ ( This). attr (' src '); IMGSRC=imgsrc.replace ("Rank_1.gif", "Rank_3.gif"); IMGSRC=imgsrc.replace ("Rank_2.gif", "Rank_4.gif"); $( This). attr (' src ', IMGSRC); }); });</script>
Then go to refresh the template file under the article page, and then put the mouse to the stars above the effect can be seen:
If it proves our first-step JS effect as shown, it has been successful.
Then we started to let the user click on the star to let the score value data into the storage, but in the storage time to add two fields we can know the score value (total score ÷ number of scores = Average score).
We first 1. To bind an event, 2. Gets the score, 3. Put this score value into storage
$ ("#rank_pic img"). Click (function(){ //get user Rating values varPingfen= ($ ( This). Prevall (). length+1)/2;//alert (pingfen); //js Mate Dede tag to remove the ID of the current document varAid={dede:field.aid/};//alert (aid); //use dede tag with JS to define a URL directly to the plus varTwourl= "{Dede:field name= ' phpurl '/}" + "/pingfen.php?aid=" +aid+ "&pingfen=" +Pingfen; //alert (twourl); //Make an Ajax request, and then use the Dsql to receive and process the data here by creating pingfen.php in the plus directory$.ajax ({type:"GET", Url:twourl, success:function(msg) {$ (' #rank '). HTML (msg); } }); });
We use AJAX to send data to the pingfen.php file in the plus directory for data processing, as shown in the code below:
<?PHPrequire_once(dirname(__file__)." /.. /include/common.inc.php "); //Receive ID $aid=$_get[' Aid ']; //Receive Ratings $pingfen=$_get[' Pingfen ']; //Modify the rating value $sql= "Update ' #@__addonmovie ' Set pingfen=$pingfenwhere aid=$aid"; //test to see if the SQL statement is correct//file_put_contents ("D:/mytest.log", $sql); if($dsql->executenonequery ($sql)){ $sql= "Select Pingfen from ' #@__addonmovie ' where aid=$aid"; $row=$dsql->getone ($sql); if(Is_array($row)){ Echo $row[' Pingfen ']; } }Else{ Echo"Score Failed"; }
Then we used to update the template file under the article page, and then to test it, the effect is as follows:
But we have found a problem, and if it comes back into the movie, it does change, as shown here:
We can not synchronize, because we have access to the second click of the buffer template file, has not been updated, so we will continue to rewrite so that the actual score and display of the score values to synchronize.
The solution can be solved by embedding a section of <script></script> code directly, and I will change the original value method:
We'll fix him a little bit, and the code looks something like this:
<li> User Rating: <font id= "Rank" > <script src= "{dede:field name= ' Phpurl '/}/pingfen.php? Flag=getpf&aid={dede:field name= ' id '/} "type=" Text/javascript "> </script> </font> min (Total <font id= "Rank_num" >...</font> people Ratings)
$ ("#rank_pic img"). Click (function(){ //get user Rating values varPingfen= ($ ( This). Prevall (). length+1)/2;//alert (pingfen); //js Mate Dede tag to remove the ID of the current document varAid={dede:field.aid/};//alert (aid); //use dede tag with JS to define a URL directly to the plus varTwourl= "{Dede:field name= ' phpurl '/}" + "/pingfen.php?flag=pingfen&aid=" +aid+ "&pingfen=" +Pingfen; //alert (twourl); //Make an Ajax request, and then use the Dsql to receive and process the data here by creating pingfen.php in the plus directory$.ajax ({type:"GET", Url:twourl, success:function(msg) {$ (' #rank '). HTML (msg); } }); });
And then modify the next pingfen.php.
<?PHPrequire_once(dirname(__file__)." /.. /include/common.inc.php "); //first receive a flag value, judging the user is to score is to take points $flag=$_get[' Flag ']; if($flag= = ' Pingfen '){ //Receive ID $aid=$_get[' Aid ']; //Receive Ratings $pingfen=$_get[' Pingfen ']; //Modify the rating value $sql= "Update ' #@__addonmovie ' Set pingfen=$pingfenwhere aid=$aid"; //test to see if the SQL statement is correct//file_put_contents ("D:/mytest.log", $sql); if($dsql->executenonequery ($sql)){ $sql= "Select Pingfen from ' #@__addonmovie ' where aid=$aid"; $row=$dsql->getone ($sql); if(Is_array($row)){ Echo $row[' Pingfen ']; } }Else{ Echo"Score Failed"; } }Else if($flag= = ' GETPF '){ //Receive aid $aid=$_get[' Aid ']; $sql= "Select Pingfen from ' #@__addonmovie ' where aid={$aid}"; $row=$dsql->getone ($sql); if(Is_array($row)){ Echo"Document.Write ('").$row[' Pingfen ']. "'); \ r\n "; } }
This problem can be solved, as long as the evaluation of how many points, then every time you come in a look, he is how many points of ...
But the new question comes again, and every time we open it, his score is OK, but the stars are uncertain, as shown below
Kill lui lei Dog---dedecms----the realization of evaluation of star function in 32dedecms movie net