Detect when input has a 'readonly' attribute

后端 未结 8 1198
感动是毒
感动是毒 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:49

    try this:

    if($('input').attr('readonly') == undefined){
        alert("foo");
    }
    

    if it is not there it will be undefined in js

提交回复
热议问题