Jquery——選擇器2
阿新 • • 發佈:2017-06-27
pla clas play spa one his code 選擇 技術
1 $("ul li:eq(3)")
選擇器
列表中等於3的元素,0開始(第四個)
1 $("ul li:lt(2)")
選擇器
列表中小於2的元素,0開始
1 $("ul li:gt(2)")
選擇器
列表中大於2的元素,0開始。
1 $("[name^=‘user‘]")
選擇器
name中以user開頭的
1 $("[name$=‘ge‘]")
選擇器
name中以ge結尾的
1 $("[name*=‘na‘]")
選擇器
name中包含na的
1 $("[name*=‘name‘][id *= ‘username‘]")
選擇器(多重)
name中包含name,且id中包含username的
1 $("input[reg]").each(function(){ 2 var val = $(this).val(); 3 var tip = $(this).attr("tip"); 4 var reg = $(this).attr("reg"); 5 var regexp = new RegExp(reg); 6 if(!regexp.test(val)){ 7 alert(tip) 8 } 9 }) 10 11 12 <input自定義選擇器type = "text" name = "username" id = "username" reg = "^\w{1,12}$" tip = "Name Input format does not conform to the requirements"/> 13 <input type = "password" name = "password" id = "password" reg = "^\w{1,12}$" tip = "PassWord Input format does not conform to the requirements"/> 14 15 <input type = "text" name = "email" id = "email" reg = "^\w*\@\w*\.\w*$" tip = "Email Input format does not conform to the requirements"/>
自定義選擇器,選擇input中含有reg屬性的。
利用正則表達式進行條件篩選。對input中的val進行判斷。
Jquery——選擇器2