【发布时间】:2017-07-18 20:54:53
【问题描述】:
有没有办法通读 HTML 页面并返回被点击的动态复选框的值?
现在,即使不使用 JS,我也知道如何从静态复选框中获取值,但由于我使用数据库中的数据生成以下复选框,因此我不确定如何确定每个复选框并知道用户选中了哪个复选框,
当我在 chrome 中浏览开发人员工具时,我可以看到生成的复选框的值发生了变化,但是当我引用它们时它仍然不起作用。
<!DOCTYPE html>
<html lang="en">
<form action="/test" method="post">
<button type="submit" id="exporst-btn" class="btn btn-primary">Import Test Data <span class="glyphicon glyphicon-import"></span></button>
<br>
<br>
<div id="table">
<table class="table table-condensed">
<thead>
<tr>
<th>Selection</th>
<th>Slno</th>
<th>Region</th>
</tr>
</thead>
<tbody>
{% for obj in TD %}
<tr>
<td>
<input type="checkbox" name="chb[]" > {{obj.OEHR_Mtest_Slno}}
</td>
<td>
{{obj.OEHR_Mtest_Slno}}
</td>
<td>
{{obj.OEHR_Mtest_SF_Part_Number}}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!--<p id="export" name="test"></p>-->
<input type="hidden" id="exp" name="test">
<button type="submit" id="export-btn" class="btn btn-success">Execute <span class="glyphicon glyphicon-play"></span></button>
</form>
</body>
<script type="text/javascript"><!--
$('#export-btn').click(function () {
alert($('#mytable').find('input[type="checkbox"]:checked').length + ' checked');
});
</script>
</html>
我可以使用上面的 JS 知道有多少个复选框被选中,我想知道被选中的复选框的值,我无法得到。
【问题讨论】:
-
值是什么意思?名字?它在哪一行?
-
@M.Davis 这个 {{obj.OEHR_Mtest_Slno}} 来自复选框旁边的服务器
-
可能会渲染输出
标签: javascript python html jinja2 flask-sqlalchemy