Detect when input has a 'readonly' attribute

后端 未结 8 1179
感动是毒
感动是毒 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-05 00:08

    You can just use the attribute selector and then test the length:

    $('input[readonly]').length == 0 // --> ok
    $('input[readonly]').length > 0  // --> not ok
    

提交回复
热议问题