php - How to exactly specify the id of td? jquery javascript -


i have many tds ,each td has id.when id variables,it failed.when id confirm(like a12),content display.then tried '#a'+i+j,but result #a921.the code is:

<script> $(document).ready(function(){ for(var i=1;i<9;i++) for(var j=1;j<21;j++) {    $('#a'+i+j).click(function (){  alert('#a'+i+j);  $('#content').css('display','block');   $('#selectid').val('#a'+i+j);   }); }    }); </script> 

who can me? a+i+j should a11 a12........a820.my php code:

<?php  function output($a,$b,$color) {  if($b)  {   echo '<td style="background-color:'.$color.'" id="'.$a.'">'.$b.'</td>';  }  else  {   echo '<td>'."n".'</td>';  } }  function cabinetcolor($a) {     if($a=="g")     {             $color=green;     }     else if($a=="gr")     {             $color=gray;     }     else if($a=="p")     {             $color=purple;     }     return $color; }   while($k<9)  {       echo '<tr>';      echo '<td width="50px" cellpadding="10px">a'.$k.'</td>';     for($j=1;$j<21;$j++)     {       $sql = "select * hpc cabinetnum='a".$k."".$j."'";       $res = $conn->query($sql);       $row = $res->fetch(pdo::fetch_num);        $color=cabinetcolor($row[45]);       output($row[1],$row[2],$color);     }   }  ?> 

of courseit #a921, because base on code when click on td, , j variables reached 9 , 21, cannot use loop problem.

instead can create function :

function dosomething(el){   alert(el.id);   $('#content').css('display','block');    $('#selectid').val(el.id); } 

and in html, call function in td tag :

echo '<td onclick="dosomething(this)" style="background-color:'.$color.'" id="'.$a.'">'.$b.'</td>' 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -