【发布时间】:2020-01-16 20:59:12
【问题描述】:
我有一个动态生成的表格,在表格加载后,我需要根据复选框在控制台中打印几行选定的行。
表格中填充了来自后端的数据。
<div class="row" style="margin-left : 8px !important;margin-right : 8px !important">
<table class="table table-bordered fixed_headers" id="Device_list">
<thead>
<tr>
<th> </th>
<th>IPADDRESS</th>
<th>DEVICE NAME</th>
<th>STATUS</th>
<th>BACKUP</th>
</tr>
</thead>
<tbody id = "all_device">
{% for item in Device_list %}
<tr>
<td><input type="checkbox" name="device_check"/></td>
<td>{{ item['ipaddress'] }} </td>
<td>{{ item['name'] }} </td>
<td>{{ item['status'] }} </td>
{% if item['backup'] == 'no_backup' %}
<td>{{ item['backup'] }}</td>
{% else %}
<td><a href="{{ url_for('backups_texts',path = item['backup']) }}">Backup</a> </td>
{% endif %}
</tr>
{% endfor %}
</tbody>
<input type="submit" id="bt" value="Show Table Data" />
</table>
function myfunc() {
console.log ("inside my function");
var valuelist = [];
$('#all_device tr').each(function() {
$(this).find("input[name='device_check']:checked").each(function() {
var values = [];
$(this).closest("td").siblings("td").each(function() {
values.push($(this).text());
});
valuelist.push(values.join(", "));
});
});
console.log("(" + valuelist.join("),(") + ")");
}
$(document).ready(function() {
$("#bt").click(function() {
myfunc();
});
});
请帮助访问表格行内容。
【问题讨论】:
-
您的代码 (
myfunc) 不起作用吗? -
你看到了什么错误?
标签: javascript python jquery html