3 回答
![?](http://img1.sycdn.imooc.com/54584d6100015f5802200220-100-100.jpg)
TA贡献1803条经验 获得超3个赞
// 在 jQuery 中
$('#chkAllowToAdminService').attr('disabled','disabled'); // Add disabled
$('#chkAllowToAdminService').removeAttr('disabled',''); // Remove disabled
// 或
$("#chkAllowToAdminService").attr("disabled",true);
$("#chkAllowToAdminService").attr("disabled",false);
// 在 JavaScript 中
document.getElementById("chkAllowToAdminService").disabled = true;
document.getElementById("chkAllowToAdminService").disabled = false;
![?](http://img1.sycdn.imooc.com/53339fdf00019de902200220-100-100.jpg)
TA贡献1853条经验 获得超9个赞
我想你可能有两个问题:
确保您具有元素的唯一 id,
'chkAllowToAdminService'
没有其他元素具有相同的 id。在您的删除属性语法中:
document.getElementById('chkAllowToAdminService').removeAttribute('disabled);
我可以看到'
最后缺少引用。
![?](http://img1.sycdn.imooc.com/54586431000103bb02200220-100-100.jpg)
TA贡献1808条经验 获得超4个赞
要删除属性,您可以使用removeAttribute(name)。在你的情况下:
const checkbox = document.querySelector('#chkAllowToAdminService')
checkbox.removeAttribute('disabled')
设置属性setAttribute(name, value)。
添加回答
举报