Input selektoru

:input selektoru formanin idare elementlerini secir - inputlar, textarealar, acilir siyahilar ve duymeler. Asagidaki teglere baxin: input, textarea, button, select. :input CSS spesifikasiyasina aid olmadigi ucun müasir brauzerlerde performansi yaxsılasdırmaq ucun evvelce elementleri saf css-selektoru ile filtrelemek, sonra ise .filter(':input') tetbiq etmek daha yaxsidir.

Sintaksis

Biz formanin idare elementlerini belə secirik:

javascript$(':input');

Numune

Gelin yuxarida qeyd olunan teoriyaya esaslanaraq, formanin butun idare elementlerini secek ve length xassesi vasitesile onlarin sayini konsola cixartaq. Biz gorəceyik ki, ora butun 13 teg daxil olub:

html<form>
  <input type="button" value="button">
  <input type="checkbox">
  <input type="file">
  <input type="hidden">
  <input type="image">
  <input type="password">
  <input type="radio">
  <input type="reset">
  <input type="submit">
  <input type="text">
  <select>
    <option>option</option>
  </select>
  <textarea></textarea>
  <button>button</button>
</form>
csstextarea {
  height: 25px;
}
javascriptlet allInputs = $(':input');
console.log('Tags amount: ' + allInputs.length);

$('form').submit(function(event) {
  event.preventDefault(); // formanin gonderilmesinin qarsisini alir
});

Həmçinin bax

  • filter metodu,
    ki, verilmis selektora gore elementler toplusunu filtreleyir
  • form tegi
  • input tegi