gpt4 book ai didi

javascript - 如何重新启用禁用的下拉列表以及如何清除文本框数据

转载 作者:行者123 更新时间:2023-11-28 08:44:44 24 4
gpt4 key购买 nike

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

不会清除文本。

任何人都可以建议问题出在哪里吗?谢谢

最佳答案

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

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

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

您忘记添加 id 选择器#

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

关于javascript - 如何重新启用禁用的下拉列表以及如何清除文本框数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19999133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com