2014-06-10 40 views
0

我想設置複選框以檢查表格的前2個表格行中的輸入字段。設置複選框以檢查前2個表格行中的輸入字段

標記

<tbody> 
<tr> 
    <td> 
    <input type="checkbox" id="" class="checkinput financeOption"><!--want this checked on page load--> 
    </td> 
     <td class="datatd"> 
     <label id="">Option 1</label> 
    </td> 
</tr> 
<tr> 
    <td> 
     <input type="checkbox" id="" class="checkinput financeOption"><!--want this checked on page load--> 
    </td> 
    </td> 
    <td class="datatd"><label id="">Option 2 </label> 
    </td> 
</tr> 
<tr> 
    <td> 
     <input type="checkbox" id="" class="checkinput financeOption"> 
    </td> 
     <td class="datatd"><label id="">Option 3</label> 
    </td> 
</tr> 

我知道我可以使用$( 「」).prop( '檢查',真);設置該屬性但figureing如何針對第2

感謝

+2

你需要爲某些r使用JavaScript陳奕迅?只要做'' - 另外,爲什麼你有空ID?這沒有意義。此外,你不應該爲你的表格使用表格。 –

+0

2個有效積分。是的,我可以將它設置爲檢查標記,但表格行是從一個對象生成的(應該提到這一點)。例如,我的ID是空的,可以從我的標記中刪除一些數據。 – Anthony

回答

2

只是切片他們:

$("[type=checkbox]").slice(0,2).prop('checked', true);