jquery遍历标签中自定义的属性方法
在开发中我们有时会对html标签添加属性,如何遍历处理?
<ul> <li name="li1" sortid="nav_1">aaaaaaa</li> <li name="li1" sortid="nav_2">bbbbbbb</li> <li name="li1" sortid="nav_3">cccccccc</li> <li name="li1" sortid="nav_4">ddddddd</li> <li name="li1" sortid="nav_5">eeeeeee</li> <li name="li1" sortid="nav_6">fffffffffffffffff</li> <li name="li1" sortid="nav_7">gggggggg</li> <li name="li1" sortid="nav_8">hhhhhhhh</li> <li name="li1" sortid="nav_9">iiiiiiiiiiiiiiiiiii</li> </ul> //以sortid来遍历 $("li[sortid^='nav_']").each(function(i){ var sortid=$(this).attr("sortid"); }); //以name来遍历 $("[name=li1]").each(function(a,b){ var sortid= $(b).attr("sortid"); }); //如果已知某个sortid要取对象 $("[sortid='nav_1']").attr("html"); $("[sortid='nav_1']").attr("name");
其他:
//查找名字是clssId的文本对象 $("input[name='clssId']").val(); //查找id有一定规律的,例如查找dd标签中id=single_xxx $("dd[id^=single_]").each(function(){ var id = $(this).attr("id"); alert(id.substring(7)); });
相关推荐
kaixinfelix 2020-10-04
liuyang000 2020-09-25
kikaylee 2020-11-11
nongfusanquan0 2020-09-23
aanndd 2020-08-12
Tips 2020-08-08
waitwolf 2020-07-30
81264454 2020-07-17
shenxiuwen 2020-07-05
roseying 2020-07-04
清溪算法君老号 2020-06-27
OldBowl 2020-06-26
dugujiujian 2020-06-25
oXiaoChong 2020-06-20
晓杰0 2020-06-14
Masimaro 2020-06-14
vincen 2020-06-12
Jasmineyaoyao 2020-06-08