問題是,即使第二個按鈕被點擊,它也只能找到第一個憑證。所以我想,如果我點擊第二個按鈕,它應該給我說按鈕的最接近的TD用戶名和密碼我想找到最接近的td,當點擊tr中的按鈕時
$(document).ready(function() {
$(".jsLoginButton").each(function() {
$(this).click(function() {
//Get login details
configuration.loginPage.LOGIN_ID = $('.loginID').closest('td').filter(':first').text();
configuration.loginPage.LOGIN_PASSWORD = $('.loginPassword').closest('td').filter(':first').text();
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<thead>
<tr>
<th style="padding: 3px">Username</th>
<th style="padding: 3px">Password</th>
<th style="padding: 3px">Action</th>
</tr>
</thead>
<tr>
<td style="padding: 3px" class="loginID">[email protected]</td>
<td style="padding: 3px" class="loginPassword">Asdf1234!</td>
<td style="padding: 3px">
<button class="jsLoginButton">login</button>
</td>
</tr>
<tr>
<td style="padding: 3px" class="loginID">[email protected]</td>
<td style="padding: 3px" class="loginPassword">Asdf1234!</td>
<td style="padding: 3px">
<button class="jsLoginButton">login</button>
</td>
</tr>
</table>
JS小提琴https://jsfiddle.net/parag_bandewar/c8w73rup/
TD你要哪個? –
最近的一個之後? –
如果我點擊第二次登錄按鈕,它應該選擇[email protected]而不是[email protected] –