Javascript/Html删除Listview中文本框的禁用属性
我有一个数据库中数据类型和地址的asp:listview。在单击按钮时,我将按钮的innerhtml更改为不同的文本,并且我需要删除类型和地址对应的输入文本框上的disabled属性。当我单击按钮时,它会删除listview中第一行的禁用属性,但不会删除我正在单击的对应行的禁用属性。例如,这里有一个listview的示例及其作用 键入“/t/t/t/t/t/t”地址 TxtBox txtboxtxtbox TxtBox EditBtn DeleteBtnJavascript/Html删除Listview中文本框的禁用属性,javascript,html,listview,Javascript,Html,Listview,我有一个数据库中数据类型和地址的asp:listview。在单击按钮时,我将按钮的innerhtml更改为不同的文本,并且我需要删除类型和地址对应的输入文本框上的disabled属性。当我单击按钮时,它会删除listview中第一行的禁用属性,但不会删除我正在单击的对应行的禁用属性。例如,这里有一个listview的示例及其作用 键入“/t/t/t/t/t/t”地址 TxtBox txtboxtxtbox TxtBox EditBtn DeleteBtn <script type="tex
<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>
TxtBox txtboxtxtbox TxtBox EditBtn DeleteBtn/**例如,如果我单击此编辑按钮,它将从非此行上方的记录中删除禁用
TxtBox txtboxtxtbox TxtBox 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>
函数更改文本(按钮){
button.innerHTML=“保存”;
document.getElementById('Type')。removeAttribute('disabled');
document.getElementById('Address')。removeAttribute('disabled');
地址
编辑
获取当前tr,而不是文档:
function changeText(button) {
var row=button.parentNode.parentNode;
button.innerHTML="Save";
row.querySelector('#Type').removeAttribute('disabled');
row.querySelector('#Address').removeAttribute('disabled');
}
不,这不起作用,parentElement不是buttonIE的选项?我改为parentNode我在FF中。parentNode也不是选项这在FF中不起作用?如果它起作用,显示结果html,我打赌它有问题。