JQuery里面的幾種選擇器 查找滿足條件的元素$("#控件ID")
更新時(shí)間:2011年08月23日 23:44:44 作者:
JQuery里面的幾種選擇器 查找滿足條件的元素$("#控件ID"),使用jquery的朋友可以參考下。
樣式:$(function (){
$("要選擇的標(biāo)簽").click(function (){alert ("彈出對(duì)話框內(nèi)容");})
});
第一種:Id選擇器
用法:
<head>
<title></title>
<script src ="Jq/jquery-1.4.2.js" type ="text/javascript" ></script>
<script type ="text/javascript">
$(function (){
$("p").click(function (){alert ("小P");})
});
</script>
</head>
<body>
<input type="button" value ="PlayGame" id="btnClick" />
<p>第一個(gè)</p>
<p>第二個(gè)</p>
</body>
說明:對(duì)所有<P>標(biāo)簽點(diǎn)擊都有彈出對(duì)話框的提示
第二種:CSS選擇器
<head>
<title></title>
<script src ="Jq/jquery-1.4.2.js" type ="text/javascript" ></script>
<script type ="text/javascript">
$(function (){
$(".warning").click(function (){alert("這是警告信息");});
});
</script>
<style type="text/css" >
.warning{background-color :Yellow ;color :Red ;}
</style>
</head>
<body>
<p>沒有警告</p>
<div class ="warning " >請(qǐng)帶好小孩</div>
<p class ="warning ">再次警告你</p>
<input class ="warning " type ="button" value ="別點(diǎn)啊" />
</body>
說明:對(duì)所有CSS樣式為:.warning點(diǎn)擊都有彈出對(duì)話框的提示
第三種:多條件選擇器
<head>
<title></title>
<script src ="Jq/jquery-1.4.2.js"></script>
<script type ="text/javascript" >
$(function (){
$(".docc,p,#txt1").click(function (){alert ("不要上當(dāng)啊");})
})
</script>
<style type="text/css" >
.docc{background-color :Fuchsia ;color :Olive ;}
</style>
</head>
<body>
<p>電腦熱賣</p>
<input type ="text" id="txt1" />
<input class ="docc" type ="button" value ="上當(dāng)" />
<input type ="checkbox" />
</body>
說明:可以對(duì)多個(gè)同時(shí)選中做處理。
$("要選擇的標(biāo)簽").click(function (){alert ("彈出對(duì)話框內(nèi)容");})
});
第一種:Id選擇器
用法:
復(fù)制代碼 代碼如下:
<head>
<title></title>
<script src ="Jq/jquery-1.4.2.js" type ="text/javascript" ></script>
<script type ="text/javascript">
$(function (){
$("p").click(function (){alert ("小P");})
});
</script>
</head>
<body>
<input type="button" value ="PlayGame" id="btnClick" />
<p>第一個(gè)</p>
<p>第二個(gè)</p>
</body>
說明:對(duì)所有<P>標(biāo)簽點(diǎn)擊都有彈出對(duì)話框的提示
第二種:CSS選擇器
復(fù)制代碼 代碼如下:
<head>
<title></title>
<script src ="Jq/jquery-1.4.2.js" type ="text/javascript" ></script>
<script type ="text/javascript">
$(function (){
$(".warning").click(function (){alert("這是警告信息");});
});
</script>
<style type="text/css" >
.warning{background-color :Yellow ;color :Red ;}
</style>
</head>
<body>
<p>沒有警告</p>
<div class ="warning " >請(qǐng)帶好小孩</div>
<p class ="warning ">再次警告你</p>
<input class ="warning " type ="button" value ="別點(diǎn)啊" />
</body>
說明:對(duì)所有CSS樣式為:.warning點(diǎn)擊都有彈出對(duì)話框的提示
第三種:多條件選擇器
復(fù)制代碼 代碼如下:
<head>
<title></title>
<script src ="Jq/jquery-1.4.2.js"></script>
<script type ="text/javascript" >
$(function (){
$(".docc,p,#txt1").click(function (){alert ("不要上當(dāng)啊");})
})
</script>
<style type="text/css" >
.docc{background-color :Fuchsia ;color :Olive ;}
</style>
</head>
<body>
<p>電腦熱賣</p>
<input type ="text" id="txt1" />
<input class ="docc" type ="button" value ="上當(dāng)" />
<input type ="checkbox" />
</body>
說明:可以對(duì)多個(gè)同時(shí)選中做處理。
您可能感興趣的文章:
相關(guān)文章
javascript jQuery $.post $.ajax用法
這是一個(gè)簡(jiǎn)單的 POST 請(qǐng)求功能以取代復(fù)雜 $.ajax 。請(qǐng)求成功時(shí)可調(diào)用回調(diào)函數(shù)。如果需要在出錯(cuò)時(shí)執(zhí)行函數(shù),請(qǐng)使用 $.ajax。2008-07-07jQuery對(duì)象和DOM對(duì)象之間相互轉(zhuǎn)換的方法介紹
這篇文章主要介紹了jQuery對(duì)象和DOM對(duì)象之間相互轉(zhuǎn)換的方法介紹,本文講解了jQuery對(duì)象轉(zhuǎn)成DOM對(duì)象、DOM對(duì)象轉(zhuǎn)換成jQuery對(duì)象 方法,需要的朋友可以參考下2015-02-02jQuery實(shí)現(xiàn)文本框郵箱輸入自動(dòng)補(bǔ)全效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)文本框郵箱輸入自動(dòng)補(bǔ)全效果,大家無需輸入完全部郵箱信息,感興趣的小伙伴們可以參考一下2015-11-11jquery實(shí)現(xiàn)人性化的有選擇性禁用鼠標(biāo)右鍵
與其使用比較暴力的手段禁用鼠標(biāo)右鍵,還不如有選擇性人性化的的禁用鼠標(biāo)右鍵,需要的朋友可以參考下2014-06-06EasyUI Datebox 日期驗(yàn)證之開始日期小于結(jié)束時(shí)間
這篇文章主要介紹了EasyUI Datebox 日期驗(yàn)證之開始日期小于結(jié)束時(shí)間,需要的朋友可以參考下2017-05-05再說AutoComplete自動(dòng)補(bǔ)全之實(shí)現(xiàn)原理
再說AutoComplete自動(dòng)補(bǔ)全之實(shí)現(xiàn)原理,這里以asp.net后臺(tái)為主,考慮到性能最好是生成xml并入緩存。2011-11-11使用jquery菜單插件HoverTree仿京東無限級(jí)菜單
這篇文章主要介紹了使用jquery菜單插件HoverTree仿京東無限級(jí)菜單,需要的朋友可以參考下2014-12-12