Javascript 无法将表td值传递给JS函数变量

Javascript 无法将表td值传递给JS函数变量,javascript,Javascript,我正在尝试将HTML的表td值传递给JS变量,但该值没有从HTML传递给JS函数 HTML- 我得到一个空值。并非所有元素都支持value属性。有关支持值属性的元素,请参见 对于td,可以将innerText用作document.getElementByIdselectedPerson.innerText使用document.getElementByIdselectedPerson.textContent而不是document.getElementByIdselectedPerson.value

我正在尝试将HTML的表td值传递给JS变量,但该值没有从HTML传递给JS函数

HTML-

我得到一个空值。

并非所有元素都支持value属性。有关支持值属性的元素,请参见


对于td,可以将innerText用作document.getElementByIdselectedPerson.innerText

使用document.getElementByIdselectedPerson.textContent而不是document.getElementByIdselectedPerson.value。td是一个容器,容器没有值PropertyTanks;如果选择了2个值,person_name.length将显示2。现在,我已更改为复选框。如果我使用person_name=document.getElementByIdselectedPerson.innerText,person_name.length不起作用。它将占用内容的长度。我想在复选框中计算我正在选择的人员的数量。
<table id="persontable" class="table table-bordered">
    <thead>
        <tr>
            <th>person name</th>
            <th>address</th>
        </tr>
    </thead>
    <tbody class="person_table">
        <% @my_persons.all.each do |person| %>
        <tr>
            <td id="selectedPerson" style="word-break:break-all;">
                <%=person.name%>
            </td>
            <td>
                <b id="person_address" style="float: right;">Not available </b>
                <!--&nbsp;&nbsp;<b id="confirm_person"></b>-->
            </td>
        </tr>
    </tbody>
</table>
function getSelectedPerson() {
    var person_name = document.getElementById("selectedPerson").value;
    alert(person_name)
}