新聞中心
jquery中eq、gt、and用法
jquery中:

寧縣ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
eq:(取指定索引的元素)
實(shí)例:
table?width="200"?cellpadding="0"?cellspacing="0"
tbody
trtdA/td/tr
trtdB/td/tr
trtdC/td/tr
trtdD/td/tr
/tbody
/table
$(document).ready(function?()?{
$('tr:eq(2)').css('background',?'#FF0000');
});
結(jié)果:取的是C
gt:(取大于指定索引的元素)
$(document).ready(function?()?{
$('ul?li:gt(2)').css('color',?'#FF0000');
});
結(jié)果:給大于2的增加一個(gè)顏色。
jQuery中并沒(méi)有and選擇器,只有andSelf。
andSelf:(將先前所選的元素加入當(dāng)前元素集合中)
$("div").find("p").andSelf().addClass("border");
結(jié)果:找到所有 div,以及其中的所有段落,并為它們添加兩個(gè)類名。
jquery 逐次判斷三個(gè)條件
body
字符1:input?type="radio"?name="str1"?value="y"?checked?是??input?type="radio"?name="str1"?value="n"???否?br?/
字符2:input?type="radio"?name="str2"?value="y"?checked?是??input?type="radio"?name="str2"?value="n"???否?br?/
字符3:input?type="radio"?name="str3"?value="y"?checked?是??input?type="radio"?name="str3"?value="n"???否?br?/
input?type="button"?onclick="test()"?value="測(cè)試"
/body
script
function?test(){
var?str1=$("[name='str1']:checked").val();
var?str2=$("[name='str2']:checked").val();
var?str3=$("[name='str3']:checked").val();
if(str1=="y"str2=="y"str3=="n"){
//觸發(fā)某個(gè)事件
alert("1");
}
if(str1=="n"str2=="y"str3=="y"){
//觸發(fā)某個(gè)事件
alert("2");
}
if(str1=="y"str2=="n"str3=="y"){
//觸發(fā)某個(gè)事件
alert("3");
}
}
/script
jquery如何實(shí)現(xiàn)一個(gè)表格的篩選,也就是按條件查找篩選
1、首先新建html文檔,向下查找兄弟標(biāo)簽:.next()。
2、jquery支持鏈?zhǔn)讲僮?,向下查找兄弟?biāo)簽的兄弟標(biāo)簽:.next().next()。
3、接著向下查找所有兄弟標(biāo)簽:nextAll(),向下查找一直找到某個(gè)條件為止:nextUntil('條件')。
4、向上查找兄弟標(biāo)簽:.prev(),向上查找所有兄弟標(biāo)簽:prevAll(),向上查找一直找到某個(gè)條件為止:prevUntil('條件')。
5、最后查找父標(biāo)簽:parent(),查找所有父標(biāo)簽:parents(),如果沒(méi)有人攔著,會(huì)一直找找到最上面的父標(biāo)簽(沒(méi)什么用),條件滿足時(shí)停止查找:parentsUntil('body') 。
jquery 多條件 選擇
看看
html xmlns=""
head
titleTestPage/title
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
script type="text/javascript" language="javascript" src="jquery-1.4.4.min.js"/script
script language="javascript" type="text/javascript"
$(document).ready(function(){
$("#btn1").click(function(){
//alert("dfafd")
$("table tr").filter(":odd").css("background-Color","red").end().filter(":even").css("background-Color","blue");
});
jQuery("#btn2").click(function(){
$("table tr:not(:first)").filter(function(){
return this.style.backgroundColor != "red";//不為紅色的tr
}).find("td:eq(1)").html("不為第一,背景不為red的行");
});
});
/script
/head
body
table
tr style="background-color:yellow"
td黃顏色行/tdtd/td
/tr
tr style="background-color:red"
td紅顏色行/tdtd/td
/tr
tr style="background-color:blue"
td藍(lán)顏色行/tdtd/td
/tr
tr style="background-color:Teal"
tdTeal顏色行/tdtd/td
/tr
tr style="background-color:Aqua"
tdAqua顏色行/tdtd/td
/tr
/table
input type="button" id="btn1" value="奇偶行背景轉(zhuǎn)換"
input type="button" id="btn2" value="選擇指定條件的行"
/body
/html
jquery多種條件篩選
script?src="jquery-1.10.2.js"/script
script
$(function(){
$("#tj1?span,#tj2?span,#gd1?span,#gd2?span,#gd3?span").click(function(){
$(this).clone(true).appendTo("#yxtj")
});
})
/script
style
span{
margin-left:10px;
}
#gd1?span,#gd2?span,#gd3?span{
display:none;
}
/style
body
div?style="background:#aaa;?color:#fff;width:60%"已選條件:
div?id="yxtj"/div
/div
div?id="tj1"
條件1:span?class="tj1"條件11/spanspan?class="tj1"條件12/spanspan?class="tj1"條件13/span
/div
div?id="tj2"
條件2:span?class="tj2"條件21/spanspan?class="tj2"條件22/spanspan?class="tj2"條件13/span
/div
div?id="gd"
更多:span?class="gd"?id="gdtj1"更多1/spanspan?class="gd"?id="gdtj2"更多2/spanspan?class="gd"?id="gdtj3"更多3/span
/div
div
div?id="gd1"
span?id="gd11"更多11/spanspan?id="gd12"更多12/spanspan?id="gd13"更多13/span
/div
div?id="gd2"
span?id="gd21"更多21/spanspan?id="gd22"更多22/spanspan?id="gd23"更多23/span
/div
div?id="gd3"
span?id="gd31"更多11/spanspan?id="gd32"更多32/spanspan?id="gd33"更多33/span
/div
/div
/body
時(shí)間倉(cāng)促,僅供參考,還有許多需要完善的地方
文章標(biāo)題:jqueryand條件,jquery語(yǔ)法基礎(chǔ)
地址分享:http://fisionsoft.com.cn/article/dsisgep.html


咨詢
建站咨詢
