gpt4 book ai didi

javascript - 使用 jquery 禁用启用按钮

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

我有一个可用的 javascript 版本来禁用/启用 from 按钮,但我无法使用 jQuery 使其工作。

我的 jsfiddle 有两个版本。 javascript 版本被注释掉。

    //NOT WORKING jQuery
function controls(id) {
if (id === "button_start") {
//$('button_start').prop('disabled','disabled');
// $('button_stop').removeProp('disabled','disabled');

// testing
$('#button_start').on('click',function() {
$(this).prop('disabled', 'disabled');
});
$('#button_stop').on('click', function(){
$(this).removeProp('disabled', 'disabled');
});

//console.log(id);

} else {
//$('button_stop').prop('disabled','disabled');
//$('button_start').removeProp('disabled','disabled');

// testing
$('#button_stop').click(function() {
$(this).prop('disabled', 'disabled');
});
$('#button_start').click(function(){
$(this).removeProp('disabled', 'disabled');
});
//console.log(id);
}
}

jsFiddle:https://jsfiddle.net/tommy6s/w2u8eskv/

感谢您的帮助!

最佳答案

这可能无法解决您的问题,但是您错误地使用了 removeProp 方法。根据 jQuery 文档,removeProp 只需要一个属性

.removeProp( propertyName )
propertyName
Type: String
The name of the property to remove.

在你的例子中,我会把你的线条改成这样

$('#button_start').click(function(){
$(this).removeProp('disabled', 'disabled');
});

对此

$('#button_start').click(function(){
$(this).removeProp('disabled');
});

https://api.jquery.com/removeProp/

此外,请记住 id 元素必须以 # 符号开头。你在你的 OP 中有它,但不在 fiddle 中。

关于javascript - 使用 jquery 禁用启用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35214150/

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