日期:2014-05-16 浏览次数:20656 次
<table width="385" height="370" border="3"> <tr> <td width="41"> </td> <td width="65">A</td> <td width="69">B</td> <td width="82">C</td> <td width="90">D</td> </tr> <tr> <td>A</td> <td>1</td> <td><select class="s1"><option>1</option><option>2</option><option>3</option></select></td> <td><select class="s1"><option>1</option><option>2</option><option>3</option></select>;</td> <td><select class="s1" name="select"> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr> <td>B</td> <td> </td> <td>1</td> <td><select class="s1" name="select2"> <option>1</option> <option>2</option> <option>3</option> </select> </td> <td><select class="s1" name="select3"> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr> <td>C</td> <td> </td> <td> </td> <td>1</td> <td><select class="s1" name="select4"> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr> <td>D</td> <td> </td> <td> </td> <td> </td> <td>1</td> </tr> </table>
<script type="text/javascript" src="http://www.coding123.net/js/jquery.js"></script> <script type="text/javascript"> $(function(){ $('select').change(function(){ var sel=$(this) ,td=sel.parent() ,table=td.closest('table') ,headTR=table.find('tr:first')//表头对象 cellIndex=td.get(0).cellIndex//所在列 ,totalSel=0; sel=sel.get(0) table.find('select').each(function(){ if(this==sel)return false; totalSel++; }); alert('前面的select数量:'+totalSel) alert('表头:'+headTR.find('td:eq('+cellIndex+')').html()) }); }); </script> <table width="385" height="370" border="3"> <tr> <td width="41"> </td> <td width="65">A</td> <td width="69">B</td> <td width="82">C</td> <td width="90">D</td> </tr> <tr> <td>A</td> <td>1</td> <td><select class="s1"><option>1</option><option>2</option><option>3</option></select></td> <td><select class="s1"><option>1</option><