Jquery——选择器2

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进行判断。

posted on 2017-06-27 17:40  kaka_79  阅读(165)  评论(0编辑  收藏  举报

导航