Instances of live support multiple click events in jquery

Source: Internet
Author: User
Tags prev

Examples of live support multiple Click events in jquery are as follows

<script>     $ (function () {             $ (' #public_ym_left '). Live (' click ', Function () {        The first number on the right of the          //< symbol       
                               var sibq=$ (' #public_ym_left ').
Next (). text ();                                   if (sibq>=1&&
sibq<=5)  var start=1;             if (sibq>5)                  var start=pArseint (SIBQ)-4;                                   $ ("#upage"). Children ().
Remove ();             var childq=$ (' <li id= ')
Public_ym_left "><a href=\ ' #\ '" " /a></li>");             var childh=$ (' <li id= ')
Public_ym_right "><a href=\ ' #\ '" " /a></li>");             var loage=$ (' <li><a  href=\ ' #\ ' " /a></li>");            
   $ ("#upage"). Append (CHILDQ);                                   for (var i=start;i< (start+5); i++)              {                 var son=$ (' <li><a id= ' page ' +i+ ' " href=\ ' #\ '"
 /a></li> ');                 $ ("#upage").
Append (son);             }       
          $ ("#upage"). Append (Loage);                 $ ("#upage").
Append (CHILDH);                 $ (' #public_ym_
Left '). Unbind ();
        });                           $ (' #public_ym_right '). Live (' click ', Function () {                            
      var sibh=$ (' #public_ym_right '). Prev (). Prev (). text ();                                                         var start
=parseint (SIBH);
            $ ("#upage"). Children (). remove ();             var childq=$ (' <li id= ') Public_ym_left "><a&Nbsp;href=\ ' #\ ' " /a></li>");             var childh=$ (' <li id= ')
Public_ym_right "><a href=\ ' #\ '" " /a></li>");             var loage=$ (' <li><a  href=\ ' #\ ' " /a></li>");            
   $ ("#upage"). Append (CHILDQ);                    
          for (var i=start;i< (parseInt (start) +5); i++)             {                 var son=$ (' <li><a id= ' page ' +i+ ')
" href=\ ' #\ '"  /a></li> ");                  $ ("#upage"). Append (son);             }       
          $ ("#upage"). Append (Loage);                 $ ("#upage").
Append (CHILDH);
            $ (' #public_ym_right '). Unbind ();
        });                    
  }); </script>


    

<div>     <ul id= "Upage" >       <li  Id= "Public_ym_left" ><a href=\ ' #\ ' "  ></a></li>                 <li><a id= "Page1"  href=\ ' #\ '  /a></li>       <li ><a id= "Page2"  href=\ ' # \ ' " /a></li>       <li><a  id=" Page3 " href= \ ' #\ '  /a></li>       <li ><a id= "Page4"   Href=\ ' #\ ' " /a></li>       <li ><a id=" Page5 "  href=\ ' #\ ' " /a></li>               <li><a href=\ ' #\ ' " /a></li>       <li  Id= "Public_ym_riGht "><a href=\ ' #\ '"  /a></li>     </ul>      <table border= "0"  cellpadding= "0"  cellspacing= "0" >         <tr>          <td width= "$" > Jump to the first < /TD>          <td width= "><input name=" "  type= "Text"  /></td>          <td width = "> Total <span>100</span> page </td>        </tr>  "    </table> </div>



The Click event Recurrence problem in jquery question: Click the Modify link, in the pop-up dialog box, click submit button, click event will execute multiple times. And with the original JS is no problem.
and after the second submission, multiple data becomes one.

Personally, the reason is that the Click event cannot be included in the Click event? I don't know if that's true.

for easy viewing, with the entire document

<! doctype html public  "-//w3c//dtd xhtml 1.0 strict//en"   "http://www.w3.org/ Tr/xhtml1/dtd/xhtml1-strict.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml " xml:lang=" ZH-CN " > <head> <title>Document</title> <meta http-equiv= "Content-type"  content= "text/ Html;charset=utf-8 " /> <meta name=" description " content=" " /> <meta name=" Keywords " content="  /> <style type= "Text/css" >     * {margin:
 0; padding: 0;}      #table  {border: 1px solid gray; border-collapse: 
collapse; width: 500px;}     tr {height: 30px;}     th {border: 1px 
Solid gray;}     td {border: 1px solid gray;text-align: center;}      td a {margin-riGht: 5px; color: blue; text-decoration: none;}      #popDiv,  #editDiv  {border: 1px solid silver; width:  315px; padding: 1px; margin-top: 10px; position: absolute; left:
 38%; z-index: 4; display: none;}     .pop p {height: 30px; margin-top: 20px; clear: both
;}     .pop a {display: block; float: right; text-decoration:
 none; font-size: 12px;}     .pop .input {height: 20px; line-height: 20px;}      /* #bottom  {width: 100%; height: 30px; margin: 0 auto;} * *      #sub  {display: block; height: 30px; margin: 0 
Auto;}     .mask {background-color:  #000;  posiTion: absolute; left: 0; top: 0; z-index: 2;} </style> <script type= "Text/javascript"  src= "//ajax.aspnetcdn.com/ajax/jquery/ Jquery-1.11.0.min.js "></script> </head> <body>     <table id=" Table ">         <tr>              <th> name </th>              <th> Age </th>              <th> position </th>             <th > Payroll </th>             <th> Operation </th >         </tr>          <tr>             <td> John </td>              <td>23</td>              <td>PHP</td>             <TD >79999</td>             <td><a  href= "#" > Modification </a></td>         </tr>          <tr>              <td> Dick </td>              <td>21</td>             <TD >Java</td>             <td>12000< /TD>              <td><a href= "#" > Modify </A></TD >         </tr>          <tr>             <td> Harry </td >             <td>34</td>              <td>Python</td>              <td>29999</td>              <td><a href= "#" > Modification </a></td>          </tr>         <TR >             <td> Zhao Liu </td>       &nbsP;      <td>37</td>              <td>Javascript</td>              <td>65450</td>              <td><a href= "#" > Modification </a></td>          </tr>     </table>     <div id= "Editdiv" >          <a href= "#" >close</a>      
   <p><strong> Name: </strong><input type= "Text"  /></p>         <p><strong> Age: </strong><input type= " Text " /></p>         <p><strong> position: </ Strong>< input type= "text"  /></p>         <p>< Strong> Salary: </strong><input type= "text"  /></p>          <input type= "button"  id= "sub"  value= "Submit"  />      </div>     <script type= "Text/javascript" >          //  Click ' Modify ' link         $ (' A.edit '). Click ( function  ()  {                                  
 var arr = [];             $ (This). Parent (). siblings (). function  ()  {              &Nbsp; arr.push ($ (this). text ());
            });             $ (' #editDiv '). Show (). "Find" (' P '). each ( function  (i)  {              
  $ (This). Find (' Input:text '). Val (Arr[i]);
            });
            var atr = $ (this);             $ (' #sub '). Click (function  ()   {                alert ('
2222222 ');                 var data
 = [];                 $ (This). Prevuntil (' A.close '). each (function  ()  {                     data.push ($ (this). Find ('
Input:text '). Val ());
                });                 data.reverse ()
;                 atr.parent (). Siblings (). each (function  (i)  {           
         $ (This). Text (Data[i]);
                });                 $ (this). Parent
(). hide ();                 $ (' Div.mask '). Remove ();
            });             //  Raw JS Implementation Click, no problem              /*document.getelementbyid (' Sub '). onclick =  function  ()  {             
   alert (' 1111111 ');                 var data
 = [];                 $ (This). Prevuntil (' A.close '). each (function  ()  {          
          data.push ($ (this). Find (' Input:text '). Val ());                  });                 data.reverse ()
;                 atr.parent (). Siblings (). each (function  (i)  {           
         $ (This). Text (Data[i]);
                });                 $ (this). Parent
(). hide ();                 $ (' Div.mask ').
Remove ();             };*/                //  Add Mask Layer    &Nbsp;        var maskheight = $ (document). Height ();             var maskwidth = $ (
Document). width ();             $ (' <div></div> '). Appendto (
$ (' body '));             $ (' Div.mask '). CSS ({                  ' width ': maskwidth,                   ' height ': maskheight,                   ' opacity ': 0.4  
           });
        });         $ (' A.close '). Click (function  () &nbSp {            $ (this). Parent (). Hide ();   
          $ (' Div.mask '). Remove ();
        });     </script> </body> </html>


Answer one:

has found the reason, I provide a method:

$ (' #sub '). Unbind (' click '). Click (function () {
    ...
});

cancels the last binding prior to each binding.

Answer two:

Find out for a long time and find out why: The

Click event has an additive binding, and whenever I call once, he adds a binding

by this method, It does solve the problem. I don't know if it's right.

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.