prihlasenyprihlasit | registrovat

:checked

kategorie: Selektory

:checked vráti: Array

Vyberie všetky elementy, ktoré sú zaškrtnuté.

:checked selektor sa používa pre checkboxy a radio buttony. Pre vybrané elementy použite :selected selektor.

Priklady:

Nájde všetky input elementy, ktoré su checked.
 <!DOCTYPE html>
<html>
<head>
  <style>
  div { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
	<form>
    <input type="checkbox" name="newsletter" checked="checked" value="Hourly" />

    <input type="checkbox" name="newsletter" value="Daily" />
    <input type="checkbox" name="newsletter" value="Weekly" />

    <input type="checkbox" name="newsletter" checked="checked" value="Monthly" />
    <input type="checkbox" name="newsletter" value="Yearly" />

  </form>
  <div></div>
<script>

    function countChecked() {
      var n = $("input:checked").length;
      $("div").text(n + (n <= 1 ? " is" : " are") + " checked!");
    }
    countChecked();
    $(":checkbox").click(countChecked);

</script>
</body>
</html>

API

© 2009 Shaddow admin hosting od VIPHosting