如何通过JQuery中的复选框获取选定列的值
How to get a value of selected column by checkbox in JQuery?
当前我从该行获得所有输出。是否可以仅获取所选"点"的值。我该怎么做?
检查时的预期输出:SF01SF02SF03
检查时的电流输出:SF0111.53.5328120.3359
<table border="1" width="100%" id="selectTable" name="selectTable">
<legend>Display Data Points</legend>
<tr>
<th></th>
<th width="40%">Point</th>
<th width="20%">Depth</th>
<th width="20%">Lat</th>
<th width="20%">Long</th>
</tr>
<tr>
<td>
<input type="checkbox" class="checkBox" name="checkBox[]" />
</td>
<td>SF01</td>
<td>11.5</td>
<td>3.5328</td>
<td>120.3359</td>
</tr>
<tr>
<td>
<input type="checkbox" class="checkBox" name="checkBox[]" />
</td>
<td>SF02</td>
<td>41.5</td>
<td>6.5328</td>
<td>113.3359</td>
</tr>
<tr>
<td>
<input type="checkbox" class="checkBox" name="checkBox[]" />
</td>
<td>SF03</td>
<td>82.1</td>
<td>5.2828</td>
<td>721.9059</td>
</tr>
</table>
<script type="text/javascript">
function clickedBox() {
var values = new Array();
$.each($("input[name='checkBox[]']:checked").closest("td").siblings("td"), function() {
values.push($(this).text());
});
document.getElementById("boxArea").value = "=====Results====='n" + values.join("'n");
}
$(document).ready(function() {
$("#selectPoint").click(clickedBox);
});
</script>
将siblings('td')
更改为next('td')
,我希望您需要将event
绑定到checkbox
。
$.each($("input[name='checkBox[]']:checked").closest("td").next("td"), function () {
//^^^^here
values.push($(this).text());
});
演示
当您说
siblings
时,它将获取第一个的所有siblings
td
,这就是您获得所有值的原因。
为了让它更简单-
使用元素上的data
属性设置您的值。
<input type="checkbox" data-value="SF02"/>
jQuery-
$(function(){
values= new Array();
$.each($('input[type="checkbox"]:checked'),function(index,item){
values.push(item.data('value');
});
});
相关文章:
- 使用springform时,如何在ajax/jquery中获取复选框值
- 使用 javascript 获取复选框的状态
- 从圣杯控制器获取复选框值
- 如何使用 JavaScript 获取复选框项的值
- 如何获取复选框值并将其插入到挖空中的可观察数组中
- <JSP>正在获取复选框的值
- 在表单提交中获取复选框值,并使用jQuery将其存储在变量中
- 获取复选框值选中-JavaScript
- Javascript - 如何获取复选框组的总和
- 如何在jquery中获取复选框选定的对象
- Javascript - 从表单中获取复选框值并获取随机结果
- 使用 jQuery 获取复选框的值为 1/0
- 如何在 Jquery 中获取复选框的 ID
- JQUERY ON('change') 获取复选框值和状态
- 如何获取复选框的文本
- 如何获取复选框值而不是所选选项
- 如何从HTML表中的多个单元格获取复选框
- 如何在 MVC-4 中的编辑模式弹出窗口中获取复选框
- Jquery,如何获取复选框未选中的事件和复选框值
- 使用 jquery 从 javascript 树中获取复选框值