繁体   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