0

我有一个数据库中数据的类型和地址的 asp:listview。在按钮单击时,我将按钮的 innerhtml 更改为不同的文本,并且我需要删除相应输入文本框上的类型和地址的 disabled 属性。发生的事情是,当我单击按钮时,它会删除列表视图中第一行的禁用属性,但不会删除我单击的那个对应的属性。例如这里是一个列表视图的例子,它在做什么

输入“/t/t/t/t/t/t/t”地址

TxtBox TxtBoxTxtBoxTxtBox EditBtn DeleteBtn

TxtBox TxtBoxTxtBoxTxtBox EditBtn DeleteBtn /**例如,如果我单击此编辑按钮,它将从上面的记录中删除禁用而不是这一行

TxtBox TxtBoxTxtBoxTxtBox EditBtn DeleteBtn

<script type="text/javascript">
        function changeText(button) { 
            button.innerHTML="Save";              
            document.getElementById('Type').removeAttribute('disabled');
            document.getElementById('Address').removeAttribute('disabled');    
</script>

<body>  
  <div>Addresses</div>
   <br />   
        <div>
    <asp:ListView runat="server" ID="ListView1" >
    <EmptyDataTemplate>No records found.</EmptyDataTemplate>
        <LayoutTemplate>
            <table id="sort" style="border:solid 1px black;width:40%;">
                <thead>
                    <tr>
                        <th>
                            <a href="#">Type</a>
                        </th>
                        <th>
                            <a href="#">Address</a>
                        </th>

                    </tr>
                </thead>
                <tbody>
                    <tr id="itemPlaceholder" runat="server" />
                </tbody>
                <tfoot>
                </tfoot>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                   <input size="8" type="text" ID="Type" disabled="disabled" value="<%# Eval("Type")%>" />
                </td>
                <td>
                   <input size="9" type="text" ID="Address" disabled="disabled" value="<%# Eval("street")%> <%# Eval("City")%> <%# Eval("State")%>" />                     
                </td>
                <td>
                   <button id="editBtn" type="button" onclick="changeText(this)">Edit</button> 
                </td>
            </tr>
        </ItemTemplate>
    </asp:ListView>
  </div>

4

1 回答 1

0

获取当前 tr,而不是文档:

  function changeText(button) { 
        var row=button.parentNode.parentNode;
        button.innerHTML="Save";              
        row.querySelector('#Type').removeAttribute('disabled');
        row.querySelector('#Address').removeAttribute('disabled');
  }
于 2013-01-31T01:32:02.223 回答