標籤:att ul li mat 定義 UI 選取器 ide closed ebe
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屬性的。
利用Regex進行條件式篩選。對input中的val進行判斷。
Jquery——選取器2