1

我在 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("disabled");

  2. $("VLANIP").val('');

    $("子网掩码").val('');

不会清除文本。

任何人都可以建议有什么问题吗?谢谢

4

1 回答 1

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('');
于 2013-11-15T10:46:16.030 回答