如何重新启用已禁用的下拉列表&如何清除文本框数据

时间:2013-11-15 10:41:13

标签: javascript jquery asp.net-mvc

我在ym asp.net mvc web应用程序中有以下html: -

<span class="f">Customer Name</span>

<select data-val="true" data-val-length="The field CustomerName must be a string with a maximum length of 50." data-val-length-max="50" data-val-required="The CustomerName field is required." id="FirewallCustomer_CustomerName" name="FirewallCustomer.CustomerName"><option value="">Choose...</option>
//code goes here…
</select>

<span class="field-validation-valid" data-valmsg-for="FirewallCustomer.CustomerName" data-valmsg-replace="true"></span>
</div>

<div>
<span class="f">VLANS</span>

<select data-val="true" data-val-number="The field CustomerVLANSID must be a number." data-val-required="The CustomerVLANSID field is required." id="FirewallCustomer_CustomerVLANSID" name="FirewallCustomer.CustomerVLANSID"><option value="">Choose..</option>
</select>

<span class="field-validation-valid" data-valmsg-for="FirewallCustomer.CustomerVLANSID" data-valmsg-replace="true"></span>

<div>
<span class="f">VLAN IP</span> <input disabled="disabled" id="VLANIP" name="VLANIP" type="text" value="" />
</div>

<div><span class="f">VLAN Sub NET Mask</span> <input disabled="disabled" id="Subnetmask" name="Subnetmask" type="text" value="" />
</div>
</div>

我有以下脚本

   $(document).ready(function () {
    $("#FirewallCustomer_CustomerVLANSID").attr("disabled", "disabled");


        $("#FirewallCustomer_CustomerName").change(function () {
            var idDC = $(this).val();
            var select = $("#FirewallCustomer_CustomerVLANSID");

             $("VLANIP").val('');
            $("Subnetmask").val('');
            select.empty();

       $("#SFirewallCustomer_CustomerVLANSID").removeAttr("disabled");
            $.getJSON("/Firewall/LoadVLANSByCustomerName", { customername: idDC },

            function (VLANData) {

                select.append($('<option/>', {
                    value: null
                }));
                $.each(VLANData, function (index, itemData) {

                    select.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });

});

但我面临以下问题: -

  1. 下拉列表不会重新显示

    $( “#SFirewallCustomer_CustomerVLANSID”)removeAttr( “无效”);

  2. $( “VLANIP”)VAL( '');

    $( “子网掩码”)VAL( '');

  3. 不会清除文字。

    任何人都可以建议问题是什么? 感谢

1 个答案:

答案 0 :(得分:0)

而不是$("#FirewallCustomer_CustomerVLANSID").attr("disabled", "disabled");$("#SFirewallCustomer_CustomerVLANSID").removeAttr("disabled");使用

$("#FirewallCustomer_CustomerVLANSID").prop("disabled", true);

$("#FirewallCustomer_CustomerVLANSID").prop("disabled", false);

您忘记添加ID选择器#

$("#VLANIP").val('');
$("#Subnetmask").val('');