簡體   English   中英

獲取表格單元格的 select 選項值

[英]Get select option value of a table cell

我在單元格中有一個帶有 select 選項類型的表格。 我想使用復選框,這樣當它被選中時,會顯示該行中的單元格。 我可以在行中顯示其他值,但我不知道如何獲取 select 選項值。

 $(document).ready(function() { $("#saverecord").click(function(event) { var currentRow = $(".btnSelect:checked").closest("tr"); var col1 = currentRow.find("td:eq(0)").text(); var col2 = currentRow.find("td:eq(1)").text(); var col3 = currentRow.find("td:eq(2)").text(); var data = col1 + "\n" + col2 + "\n" + col3; console.log(data); alert(data); }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table name="mytable" id="mytable"> <tr> <th>year</th> <th>item</th> <th>type</th> <th>checked</th> </tr> <tr> <td>2020</td> <td>shoe</td> <td> <select name="test1" id="test1"> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> </td> <td><input type="checkbox" class="btnSelect" id="chk" name="chk" /></td> </tr> </table> <input type="button" value="Save the record" id="saverecord" class="button0">

我假設您正在使用 jQuery 來獲取 select 字段的值:

$("#test1").val()

暫無
暫無

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

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