jQuery Form Element Selector Code Example
- 2021-07-16 01:46:52
- OfStack
This article example shares the specific code of jQuery form element selector for your reference, the specific content is as follows
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="imooc.css" type="text/css">
<style>
input{
display: block;
margin: 10px;
padding:10px;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
<h2> Child Element Filter Selector </h2>
<h3>input , text , password , radio , checkbox</h3>
<h3>submit , image , reset , button , file</h3>
<div class="left first-div">
<form>
<input type="text" value="text Type "/>
<input type="password" value="password"/>
<input type="radio"/>
<input type="checkbox"/>
<input type="submit" />
<input type="image" />
<input type="reset" />
<input type="button" value="Button" />
<input type="file" />
</form>
</div>
<script type="text/javascript">
// Find all input, textarea, select And button Element
//:input The selector basically selects all form controls
$(':input').css("border", "3px groove blue");
</script>
<script type="text/javascript">
// Match all input Element of type is text Adj. input Element
$('input:text').css("background", "#A2CD5A");
</script>
<script type="text/javascript">
// Match all input Element of type is password Adj. input Element
$('input:password').css("background", "yellow");
</script>
<script type="text/javascript">
// Match all input Radio buttons in the element , And select
$('input:radio').attr('checked','true');
</script>
<script type="text/javascript">
// Match all input Check buttons in the element , And select
$('input:checkbox').attr('checked','true');
</script>
<script type="text/javascript">
// Match all input Submit button in the element , Modify the background color
$('input:submit').css("background", "#C6E2FF");
</script>
<script type="text/javascript">
// Match all input Elements of the image type in the element , Modify the background color
$('input:image').css("background", "#F4A460");
</script>
<script type="text/javascript">
// Match all input Element of type button in element
$('input:button').css("background", "red");
</script>
<script type="text/javascript">
// Match all input Element of type is file Elements of
$('input:file').css("background", "#CD1076");
</script>
</body>
</html>