0

我有一个列表视图,其中包含一个下拉列表、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>
            &nbsp;&nbsp;<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');
            }
});
4

3 回答 3

1

是否像为文本框设置 ID 并通过以下方式访问它们一样简单:

document.getElementById('yourtextboxid').value

或者

document.yourformname.yourtextboxname.value

或者

$('#yourtextboxid').val()
于 2013-03-12T20:13:25.663 回答
0

您可以使用 find 函数在 DOM 中深入查找元素

var zipNode = parent.find(".zip");
于 2013-03-12T20:10:27.587 回答
0

只需通过 ID 访问 zipNode:

var zipNode = parent.find("#zip");
于 2013-03-12T20:13:01.123 回答