2017-04-19 55 views
0

嗨我已經看到了循環的基本知識,但是,當循環訪問特定複選框時,除了下面的基本循環功能外,還將在jQuery代碼中添加什麼內容?就像我可以用什麼來特別循環一組複選框。謝謝。我在下面添加了複選框的HTML格式。通過一組特定的文本框循環訪問

$("A").each(function(index) { console.log(index + ": " + $(this).text()); });

<td class="dot_wrap"> 
      <label for="A1"><span class="hidden">A-1</span> 
       <input type="checkbox" value="A1" name="A1" id="A1" tabindex="1" class="A"> 
       <span aria-hidden="true">&nbsp;</span> 
      </label> 
     </td> 

     <td class="dot_wrap"> 
      <label for="A4"><span class="hidden">A-4</span> 
       <input type="checkbox" value="A4" name="A4" id="A4" tabindex="4" class="A"> 
       <span aria-hidden="true">&nbsp;</span> 
      </label> 
     </td> 

     <td class="dot_wrap"> 
      <label for="A2"><span class="hidden">A-2</span> 
       <input type="checkbox" value="A2" name="A2" id="A2" tabindex="2" class="A"> 
       <span aria-hidden="true">&nbsp;</span> 
      </label> 
     </td> 

     <td class="dot_wrap"> 
      <label for="A5"><span class="hidden">A-5</span> 
       <input type="checkbox" value="A5" name="A5" id="A5" tabindex="5" class="A"> 
       <span aria-hidden="true">&nbsp;</span> 
      </label> 
     </td> 

    <td class="dot_wrap"> 
     <label for="A3"><span class="hidden">A-3</span> 
      <input type="checkbox" value="A3" name="A3" id="A3" tabindex="3" class="A"> 
      <span aria-hidden="true">&nbsp;</span> 
     </label> 
    </td> 

    <td class="dot_wrap"> 
     <label for="A6"><span class="hidden">A-6</span> 
      <input type="checkbox" value="A6" name="A6" id="A6" tabindex="6" class="A"> 
      <span aria-hidden="true">&nbsp;</span> 
     </label> 
    </td> 
+0

在選擇器中添加點以使其按類選擇:'$(「.A」)' – trincot

回答

1

使用普通CSS選擇器的工作原理:

$('input[type=checkbox]') 

jQuery的也有這樣的special :checkbox selector

$('input:checkbox') 

如果你想將它縮小到你的班級A,你可以在選擇器中添加:

$('input.A[type=checkbox]') 
$('input.A:checkbox') 

或者,如果你有他們的所有節點(與例如ID的形式)下聚集,也可以縮小它使用選擇器功能的第二個參數:

$('input:checkbox', '#my-form') 

而且還有類選擇器:

$('input.A:checkbox', '#my-form')