gpt4 book ai didi

Jquery 禁用 HTML 按钮不起作用

转载 作者:行者123 更新时间:2023-12-03 22:57:13 25 4
gpt4 key购买 nike

如果下拉列表是某个值,我试图使用一些 jQuery 来禁用表单上的确认按钮,但它似乎不起作用。

我在这里阅读了很多帖子并尝试了各种不同的方法。

这是我目前的代码:

    <script>
$(document).ready(function () {
// Handler for .ready() called.
$('#MoveToCompanyId').attr("disabled", true);

$('#DeleteAll').live("click", function () {

if ($(this).attr("value") == "True") {
$('#MoveToCompanyId').attr("disabled", true);
} else {
$('#MoveToCompanyId').attr("disabled", false);
$('#confirm').attr("disabled", true);
$('#MoveToCompanyId').change(function () {
if ($("#MoveToCompanyId option:selected").text() != "---Select Company---") {
$('#confirm').removeAttr("disabled");
alert($("#MoveToCompanyId option:selected").text());
}
else {
$('#confirm').attr("disabled", true);
alert("I should be disabled!");
}

});
}
});
});

</script>

谁能看出它有什么问题吗?

为了澄清,我知道当我的警报正在工作时它会进入正确的代码块。只是禁用按钮不起作用。

亲切的问候,

加雷斯

最佳答案

你应该使用

prop('disabled',true)
prop('disabled',false)

如果您使用的是 jQuery 1.6+,那么您应该使用 prop.

了解更多关于prop的信息

Properties generally affect the dynamic state of a DOM element without changing the serialized HTML attribute. Examples include the value property of input elements, the disabled property of inputs and buttons, or the checked property of a checkbox. The .prop() method should be used to set disabled and checked instead of the .attr() method. The .val() method should be used for getting and setting value.

关于Jquery 禁用 HTML 按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11033945/

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