ドキュメント

Selectors/input

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

:input

Matches all input, textarea, select and button elements.
Examples:

Finds all input elements.

    var allInputs = $(":input");
    var formChildren = $("form > *");
    $("#messages").text("Found " + allInputs.length + " inputs and the form has " +
                             formChildren.length + " children.");
			
	// so it won't submit
    $("form").submit(function () { return false; }); 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    
    var allInputs = $(":input");
    var formChildren = $("form > *");
    $("#messages").text("Found " + allInputs.length + " inputs and the form has " +
                             formChildren.length + " children.");
			
	// so it won't submit
    $("form").submit(function () { return false; }); 

  });
  </script>
  <style>
  textarea { height:25px; }
  </style>
</head>
<body>
  <form>
    <input type="button" value="Input 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>
  <div id="messages">
  </div>
</body>
</html>

NameType