Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
Detectar cuando la entrada tiene un atributo de 'solo lectura'

Quiero lanzar una alerta cuando una entrada tiene un atributo de 'solo lectura'. He intentado esto:

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

Creo que 'si' ni siquiera es la mejor manera de hacerlo.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

La forma más rápida es usar la función .is() jQuery.

 if ( $('input').is('[readonly]') ) { }

usar [readonly] como selector simplemente verifica si el atributo está definido en su elemento. si desea verificar un valor, puede usar algo como esto en su lugar:

 if ( $('input').is('[readonly="somevalue"]') ) { }
over 4 years ago · Santiago Trujillo Report

0

Desde JQuery 1.6, siempre use .prop() Lea por qué aquí: http://api.jquery.com/prop/

 if($('input').prop('readonly')){ }

.prop() también se puede usar para establecer la propiedad

 $('input').prop('readonly',true); $('input').prop('readonly',false);
over 4 years ago · Santiago Trujillo Report

0

¿Qué pasa con javascript sin jQuery?

para cualquier entrada que pueda obtener con o sin jQuery, simplemente:

 input.readOnly

nota: mente camelloCase

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!