jQuery表單元素選擇器代碼實例
更新時間:2017年02月06日 10:50:20 投稿:lijiao
這篇文章主要為大家詳細介紹了jQuery表單元素選擇器代碼實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jQuery表單元素選擇器的具體代碼,供大家參考,具體內(nèi)容如下
<!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>子元素篩選選擇器</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類型"/>
<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">
//查找所有 input, textarea, select 和 button 元素
//:input 選擇器基本上選擇所有表單控件
$(':input').css("border", "3px groove blue");
</script>
<script type="text/javascript">
//匹配所有input元素中類型為text的input元素
$('input:text').css("background", "#A2CD5A");
</script>
<script type="text/javascript">
//匹配所有input元素中類型為password的input元素
$('input:password').css("background", "yellow");
</script>
<script type="text/javascript">
//匹配所有input元素中的單選按鈕,并選中
$('input:radio').attr('checked','true');
</script>
<script type="text/javascript">
//匹配所有input元素中的復(fù)選按鈕,并選中
$('input:checkbox').attr('checked','true');
</script>
<script type="text/javascript">
//匹配所有input元素中的提交的按鈕,修改背景顏色
$('input:submit').css("background", "#C6E2FF");
</script>
<script type="text/javascript">
//匹配所有input元素中的圖像類型的元素,修改背景顏色
$('input:image').css("background", "#F4A460");
</script>
<script type="text/javascript">
//匹配所有input元素中類型為按鈕的元素
$('input:button').css("background", "red");
</script>
<script type="text/javascript">
//匹配所有input元素中類型為file的元素
$('input:file').css("background", "#CD1076");
</script>
</body>
</html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery 行背景顏色的交替顯示(隔行變色)實現(xiàn)代碼
主要是利用了jquery的attr為行添加樣式來實現(xiàn)的,具體的代碼如下。2009-12-12
jQuery mobile在頁面加載時添加加載中效果 document.ready 和window.onload執(zhí)行順序
這篇文章主要介紹了jQuery mobile在頁面加載時添加加載中效果 document.ready 和window.onload執(zhí)行順序比較,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07
jquery判斷iPhone、Android設(shè)備類型
這篇文章主要為大家詳細介紹了jquery實現(xiàn)iPhone、Android設(shè)備判斷方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
jQuery Ajax實現(xiàn)Select多級關(guān)聯(lián)動態(tài)綁定數(shù)據(jù)的實例代碼
這篇文章主要介紹了jQuery Ajax實現(xiàn)Select多級關(guān)聯(lián)動態(tài)綁定數(shù)據(jù)的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-10-10

