簡體   English   中英

如何顯示單選按鈕選擇中列出的用戶名和密碼?

[英]How can I display the username and password that i listed on radio button selection?

我想顯示在標簽字段下面選擇單選按鈕的特定行的用戶名和密碼,我也想將它們存儲在變量中。 那么我該如何實現呢?

<!DOCTYPE html>
<html>
<head>
    <title>TESTING</title>
</head>
<body>
<table>
    <tr>
        <th>UserName</th>
        <th>Password</th>
        <th>Select</th>
    </tr>
    <tr>
        <td>Ram</td>
        <td>password1</td>
        <td><input type="radio" name="radioButton1"></td>
    </tr>
    <tr>
        <td>Shyam</td>
        <td>password1</td>
        <td><input type="radio" name="radioButton2"></td>
    </tr>
</table>
<br>
<br>
<label>The username is: </label>
<br>
<label>The password is: </label>
</body>
</html>

您是新手,因此請嘗試使用此jquery代碼。

$('input[name=radioButton]').on('change', function () {
      if ($(this).val() == 'FirstUser') {
            $('.user').text($(this).closest('tr').find('td:eq(0)').text());
            $('.pass').text($(this).closest('tr').find('td:eq(1)').text());
    } else  {
            $('.user').text($(this).closest('tr').find('td:eq(0)').text());
            $('.pass').text($(this).closest('tr').find('td:eq(1)').text());
    }
});

這里的小提琴鏈接..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM