我有一个列表视图,其中包含一个下拉列表、3 个文本框、1 个包含在跨度中以切换可见性和 2 个按钮的文本框。我无法访问包含在跨度中的文本框的值和属性值。这可能与我尝试访问它的方式有关。任何帮助表示赞赏。
这是列表视图:
<asp:ListView runat="server" ID="ListView1">
<LayoutTemplate>
<table id="tablesorter" style="border: solid 1px black; width: 55%;">
<thead>
<tr>
<th>
<a href="#">Country</a>
</th>
<th>
<a href="#">Info.</a>
</th>
<th>
<a href="#">Action</a>
</th>
</tr>
</thead>
<tbody>
<tr id="itemPlaceholder" runat="server" />
</tbody>
<tfoot>
</tfoot>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<select id="Existing" data="<%# Eval("Type").ToString()%>"
class="Existing" style="width: 90px">
<option value="0">USA</option>
<option value="1">CAN</option>
<option value="2">MEX</option>
</td>
<td>
<input size="4" data="" type="text" id="city" value="<%# Eval("City")%>" />
<input size="4" data="" type="text" id="state" value="<%# Eval("State")%>" />
<input size="4" data="" type="text" id="Phone" value="<%# Eval("PhoneNbr")%>" />
<span class="ZipBox" id="ZipBox" style="visibility: hidden">
<input maxlength="5" data="" class="zip" size="5" type="text" id="zip" value="<%# Eval("ZIP")%>" />
</span>
</td>
<td>
<2 buttons here>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
这是我的 Javascript,我在其中访问所有文本框的值等按钮单击...
$(.updatebuttonclick)
.click(function() {
var parent = $(this).parent().prev();
var tr = $(this).closest('tr');
var TypeNode = tr.find("select.Existing").first();
var cityNode = parent.children(".city").first();
var stateNode = parent.children(".state").first();
var phoneNode = parent.children(".phone").first();
var zipNode = parent.children(".zip").first();
var newcity = cityNode.val();
var originalcity = cityNode.attr('data');
var newstate = stateNode.val();
var originalstate = stateNode.attr('data');
var newphone = phoneNode.val();
var originalphone = phoneNode.attr('data');
//check for business type for extension
if (newcity == "2") {
var newzip = zipNode.val();
var originalzip = zipNode.attr('data');
}
});