Let's take a look at it first.
The top of this blog is to use a plug-in prepared by others. This effect was used last week and I went to study it. The following is a step-by-step implementation of the entire effect ....
Demo page implementation
XML/HTML code
- <DivClass = "digg" id = "digg">
- <DivClass = "good"> <Href = "#">
- <P>This document is good.</P>
- <DivClass = "bar">
- <DivId = "g_img" style = "width: 70%"> </Div>
- </Div>
- <SpanClass = "num" id = "num">70% (7000)</Span> </A> </Div>
- <DivClass = "bad"> <Href = "#">
- <P>Document to be improved</P>
- <DivClass = "bar">
- <DivId = "B _img" style = "width: 30%"> </Div>
- </Div>
- <SpanClass = "num">30% (3000)</Span> </A> </Div>
- </Div>
The main point is to control the g_img width by percentage. css code will not be pasted out.
Check the demo.
With the demo, other implementations are much more convenient. First, the page gets html. The page is loaded for the first time, and the background data is obtained using ajax instead of being directly displayed. (Asp is used as the background language for convenience of testing)
The following is the html code output by asp.
XML/HTML code
- Function getdigshtml () 'output html
- Dim rsajax, SQL, str, digsnum, undigsnum, digsnumall, digsper, undigsper
- Set rsajax = server. CreateObject ("adodb. recordset ")
- SQL = "select * from dig where id = 1"
- Rsajax. open SQL, conn, 1, 1
- Digsnum = rsajax ("digs ")
- Undigsnum = rsajax ("undigs ")
- If isnull (digsnum) then digsnum = 0
- If isnull (undigsnum) then undigsnum = 0
- Digsnumdigsnumall = digsnum + undigsnum
- If digsnumall = 0 then
- Digsper = 0
- Undigsper = 0
- Else
- Digsper = FormatNumber (cint (digsnum)/cint (digsnumall), 3) * 100
- Undigsper = FormatNumber (cint (undigsnum)/cint (digsnumall), (3) * 100
- End if
- Str = "<div class = 'good'>"
- Strstr = str &"<Href = JavaScript: isdigs ('digs ')>"
- Strstr = str &"<P>This document is good.</P> <DivClass = 'bar'> <DivId = 'G _ img 'style = 'width: "& digsper &" %'> </Div> </div>"
- Strstr = str &"<SpanClass = 'num'>"& Digsper &" % ("& digsnum &")</Span>"
- Strstr = str &"</A> </div> <divClass = 'bad'>"
- Strstr = str &"<Href = JavaScript: isdigs ('undigs ')>"
- Strstr = str &"<P>Document to be improved</P> <divClass = 'bar'> <DivId = 'B _ img' style = 'width: "& undigsper &" %'> </Div> </div>"
- Strstr = str &"<SpanClass = 'num'>"& Undigsper &" % ("& undigsnum &")</Span>"
- Strstr = str &"</A> </div>"
- Getdigshtml = str
- End function
After the output is complete, we will get the result from the front end. At this time, we will use jquery ajax. Why not use ajax directly? The reason is very simple. I won't ..... Let's take a look at the ajax code in jquery, which is very simple.
JavaScript code
- Function getdigshtml () // obtain the top level and step on the html
- {
- $. Ajax ({
- Type: 'post ',
- Url: 'digg. asp ',
- Data: 'Action = getdigshtml ',
- Success: function (msg ){
- $ ("# Digg" cmd.html (msg );
- }
- })
- }
The output is complete, and the next step is the digs and undigs operations, which is similar to getting html code.
JavaScript code
- FunctionIsdigs (digtype) // click it to perform the operation.
- {
- $. Ajax ({
- Type: 'post ',
- Url: 'digg. asp ',
- Data: 'Action = digs & digtype = '+ digtype,
- /* BeforeSend: function (){
- $ ("# Vote"). hide ();
- $ ("# Loadings"). show ();
- }. The ajax request displays the loading effect */
- Success:Function(Msg ){
- Switch(Msg)
- {
- /* The backend is used to determine
- Case '1 ':
- $ ("# Loadings"). hide ();
- $ ("# Vote"). show ();
- Alert ("Please log on first! ");
- Break;
- Case '2 ':
- $ ("# Loadings"). hide ();
- $ ("# Vote"). show ();
- Alert ("Download it first before proceeding! ");
- Break;
- Case '4 ':
- $ ("# Loadings"). hide ();
- $ ("# Vote"). show ();
- Alert ("You have participated in the evaluation! ");
- Break ;*/
- Case'3 ':
- Getdigshtml (); // rebind html
- // $ ("# Loadings"). Hide ();
- // $ ("# Vote"). Show ();
- Alert ("Thank you for your participation! ");
- Break;
- Default:
- }
- }
- })
- }
Commented out code: part of the code is used for legal verification of Background Data. The beforeSend method is related to the operations before the ajax request is executed (for loading more)
The last step is to re-obtain and bind the getdigshtml () after each data submission and return a successful result, thus ensuring the real-time data.
Let's take a look at the final effect. I will download the demo.