Detect when input has a 'readonly' attribute

后端 未结 8 1206
感动是毒
感动是毒 2021-02-04 23:12

I want to throw an alert when an input has a \'readonly\' attribute. I have tried this:

  if($(\'input\').attr(\'readonly\') == \'readonly\'){

    alert(\"foo\"         


        
8条回答
  •  春和景丽
    2021-02-04 23:55

    what about javascript without jQuery ?

    for any input that you can get with or without jQuery, just :

    input.readOnly
    

    note : mind camelCase

提交回复
热议问题