javascript - How to disable html table row -


if click 3 times html table same row means.. want disable/hide row.. click count reset when page reload.. using pure javascript

my code:

                                                               window.onload=function found(row) {              var table=document.getelementbyid("main");              var rows = table.rows;              (var = 0; < rows.length; i++) {                   rows[i].onclick = (function() { // closure                      var cnt = i; // save counter use in function                           return function() {                             var result = this.cells[i];                             alert("you want choose "+result.innerhtml);                           }                     })(i);                 }             }
<html>  <head>      <title>untitled</title>    <body>    <table id="main"><tr>      <td>1</td>      <td>2</td>      <td>3</td>      <td>4</td>  </tr><tr>      <td>5</td>      <td>6</td>      <td>7</td>      <td>8</td>  </tr><tr>      <td>9</td>      <td>10</td>      <td>11</td>      <td>12</td>  </tr></table>    </body>  </html>

you can keep number of counts remaining in closure create on each onclick handler. then, when count reaches 0, hide row. this:

var numberofclicks = 3; var table=document.getelementbyid("main"); var rows = table.rows; (var = 0; < rows.length; i++) {     rows[i].onclick = (function(cnt) { // closure         return function() {             if (--cnt == 0) {                 this.style.display = 'none';             }         }     })(numberofclicks); } 

see demo


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -