Disable/enable an input with jQuery?

后端 未结 18 2736
礼貌的吻别
礼貌的吻别 2020-11-21 07:47
$input.disabled = true;

or

$input.disabled = \"disabled\";

Which is the standard way? And, conversely, how do yo

18条回答
  •  我寻月下人不归
    2020-11-21 07:50

    Update for 2018:

    Now there's no need for jQuery and it's been a while since document.querySelector or document.querySelectorAll (for multiple elements) do almost exactly same job as $, plus more explicit ones getElementById, getElementsByClassName, getElementsByTagName

    Disabling one field of "input-checkbox" class

    document.querySelector('.input-checkbox').disabled = true;
    

    or multiple elements

    document.querySelectorAll('.input-checkbox').forEach(el => el.disabled = true);
    

提交回复
热议问题