jQuery基本選擇器和層次選擇器學習使用
更新時間:2017年02月27日 11:12:10 作者:rain_web
這篇文章主要介紹了jQuery基本選擇器和層次選擇器的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jQuery選擇器的具體實現代碼,供大家參考,具體內容如下
1. 基本選擇器

<html>
<head>
<meta charset="utf-8">
<title>jQuery基本選擇器</title>
<script type="text/javascript" src="js/jquery-1.x.js"> </script>
</head>
<body>
<div id="idDiv">DOM對象與jQuery對象的相互轉化</div>
<div class="classDiv">jQuery對象不能直接使用DOM對象的方法,</div>
<div class="classDiv">但可以通過將jQuery對象轉換成DOM對象后再調用其方法。</div>
<span class="classSpan">基本選擇器是jQuery中最常用的選擇器</span>
<script type="text/javascript">
$(function(e){
$("#idDiv").css("color","blue");
$(".classDiv").css("background-color","#dddddd");
$("span").css("background-color","gray").css("color","white");
$("*").css("font-size","20px");
$("#idDiv,.classSpan").css("font-style","italic");
});
</script>
</body>
</html>
2. 層次選擇器

<html>
<head>
<meta charset="utf-8">
<title>jQuery層次選擇器</title>
<script type="text/javascript" src="js/jquery-1.x.js"> </script>
</head>
<body>
<div>
搜索條件<input name="search" />
<form>
<label>用戶名:</label>
<input name="useName" />
<fieldset>
<label>密 碼:</label>
<input name="password" />
</fieldset>
</form>
<hr/>
身份證號:<input name="none" /><br/>
聯系電話:<input name="none" />
</div>
<script type="text/javascript">
$(function(e){
$("form input").css("width","200px");
$("form > input").css("background","pink");
$("label + input").css("border-color","blue");
//$("label").next("input").css("border-color","blue");
$("form ~ input").css("border-bottom-width","8px");
//$("form").nextAll("input").css("border-bottom-width","4px");
$("*").css("padding-top","3px");
});
</script>
</body>
</html>
效果圖

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
jQuery Form插件使用詳解_動力節(jié)點Java學院整理
這篇文章主要為大家詳細介紹了jQuery Form插件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07

