【发布时间】:2016-03-25 17:42:29
【问题描述】:
我对 jquery 或任何网络技术都很陌生。
这是我的 HTML 代码:
<form id = "featureform">
<!-- Table inside the form -->
<table id="mytable" class="table table-striped">
<!-- First Row -->
<tr id = "tableRow1">
<td><input id="from_checkbox" class="form-input-checkbox" type="checkbox" checked
data-toggle="toggle" data-on="From" data-off="From"></td>
<td><input type="text" id="from_text" value="tester@test.com"></td>
</tr>
<!-- Second Row -->
<tr id = "tableRow2">
<td><input id="to_checkbox" class="form-input-checkbox" type="checkbox" checked
data-toggle="toggle" data-on="To" data-off="To"></td>
<td><input type="text" id="to_text" value="myself@dummy.com"></td>
</tr>
</table>
</form>
所以我在表单中有一个表格。表格的每一行有 2 列。第一列将包含一个 bootstrap toggle 复选框。文本字段将保存该特定复选框的值。两种输入类型(复选框和文本字段)都有关联的 id。
这是我想做的:
此处需要帮助:当用户切换复选框时,我想知道复选框和文本字段的“id”。
此表将包含多行,因此基于 ID 对每一行进行硬编码不是解决方案。我正在寻找一个看起来像这样的通用解决方案:
//form-input-checkbox is the class name assigned for every checkbox. So we monitor any events coming from these
// checkboxes, and do the magic
$(".form-input-checkbox").change(function(){
// Extract the id of the checkbox
// Extract the id of the textfield in this row
console.log($(this).closest("tr"));
});
【问题讨论】:
标签: javascript jquery html twitter-bootstrap checkbox