目前,我从该行获取所有输出。是否只能获取所选“点”的值。我怎样才能做到这一点?

检查时的预期输出:
SF01
SF02
SF03

检查时的电流输出:
    SF01
    11.5
    3.5328
    120.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());
});


DEMO


  当您说siblings时,它将获取第一个的所有siblings
  td,这就是为什么要获取所有值的原因。

07-24 09:46
查看更多