Javascript 单击添加自动编号1,2,3-----

Javascript 单击添加自动编号1,2,3-----,javascript,jquery,Javascript,Jquery,HTML: 加 ID在HTML中必须是唯一的为什么不能使用类选择器?将代码粘贴到FIDLE上最好是识别 <table> <tr> <th><b>ADD</b></th> <tr><td class = "tdCustom" ><apex:commandButton value="Add" action="{!addBatch}" id="update" </

HTML:


ID在HTML中必须是唯一的为什么不能使用类选择器?将代码粘贴到FIDLE上最好是识别
<table>
    <tr>
    <th><b>ADD</b></th>
    <tr><td class = "tdCustom" ><apex:commandButton value="Add" action="{!addBatch}" id="update"    </td></tr>
    <td class = "tdCustom" style="width:100px;">          
    <apex:repeat value="{!batchMap[qliRow]}" var="child" id="therepeat2">
    <table class="table-data" border = "1">
    <apex:variable value="{!1}" var="batchrowNum"/>
    <tr id="tr_clone">                                     
    <td> <apex:input value="0" id="counter"/></td>
    <td>
    <apex:commandButton value="Delete" action="{!deleteBatch}" />
    </td></tr>
    <apex:variable var="batchrowNum" value="{!batchrowNum+ 1}"/>
    </table>
    </apex:repeat>
    </td>
    </tr>
    <apex:variable var="rowNum" value="{!rowNum + 1}"/> 
    </apex:repeat> 
    </apex:repeat> 
    </table>  
<script>
var val;
$("#update").click(function()
{
   val = $('#counter').val();
   val++;
   $('#counter').prop('value',val )
});
</script>