Javascript 如何重新启用已禁用的dropdownlist&;如何清除文本框数据

Javascript 如何重新启用已禁用的dropdownlist&;如何清除文本框数据,javascript,jquery,asp.net-mvc,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 Cus

我在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>
客户名称
选择。。。
//代码在这里…
虚拟局域网
选择。。
虚拟局域网IP
VLAN子网掩码
我有以下脚本

   $(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
                    }));
                });
            });
        });

});
$(文档).ready(函数(){
$(“#FirewallCustomer_CustomerLansid”).attr(“禁用”、“禁用”);
$(“#FirewallCustomer_CustomerName”)。更改(函数(){
var idDC=$(this.val();
var select=$(“#防火墙客户_CustomerVLANSID”);
$(“VLANIP”).val(“”);
$(“子网掩码”).val(“”);
select.empty();
$(“SFirewallCustomer\u CustomerVLANSID”).removeAttr(“禁用”);
$.getJSON(“/Firewall/LoadVLANSByCustomerName”,{customername:idDC},
功能(VLAN数据){
select.append($(''){
值:null
}));
$.each(VLAN数据、函数(索引、itemData){
select.append($(''){
value:itemData.value,
text:itemData.text
}));
});
});
});
});
但我面临以下问题:-

  • 下拉列表将不会被重新编辑

    $(“SFirewallCustomer\u CustomerVLANSID”).removeAttr(“禁用”)

  • $(“VLANIP”).val(“”)

    $(“子网掩码”).val(“”)

  • 不会清除文本

    有人能告诉我问题出在哪里吗? 谢谢您,而不是
    $(“FirewallCustomer\u CustomerLansid”).attr(“disabled”、“disabled”)
    $(“#SFirewallCustomer_CustomerVLANSID”).removeAttr(“禁用”)使用

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

    您忘记添加id选择器
    #


    根据您使用的jq版本,您应该使用
    .prop('disabled',true)
    .prop('disabled',false)
    但我可以在脚本文件的第一行禁用它,但我无法重新启用它?我使用的是1.8.2 javascript version.ya,不要删除属性,按照首选方法使用
    .prop()
    将其设置为false确定我更改了它,但“prop('disabled',true)”将禁用,而prop('disabled',false)将不会重新启用它。。。所以我也有同样的问题。任何adive?
    .prop('disabled',false)
    都应重新启用它$(“#FirewallCustomer_CustomerVLANSID”).prop(“disabled”,true);将禁用它,,,但$(“#FirewallCustomer_CustomerLansid”).prop(“已禁用”,false);不会重新启用它…可能是因为您以前清空了()它?我觉得这不好。
    $("#FirewallCustomer_CustomerVLANSID").prop("disabled", false);
    
    $("#VLANIP").val('');
    $("#Subnetmask").val('');