English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A veces, en el desarrollo, agregamos atributos a las etiquetas HTML, ¿cómo recorrer y procesarlas?
<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> //Recorrer con sortid $("li[sortid^='nav_']").each(function(i){ var sortid=$(this).attr("sortid"); }); //)] $("[name=li1']).each(function(a,b){ var sortid= $(b).attr("sortid"); }); //Si se conoce algún sortid para obtener el objeto $("[sortid='nav_1']).attr("html"); $("[sortid='nav_1']).attr("name");
Otras:
//Buscar el objeto de texto con el nombre clssId $("input[name='clssId']").val(); //Buscar id con un patrón regular, por ejemplo, buscar tags dd con id=single_xxx $("dd[id^=single_]").each(function(){ var id = $(this).attr("id"); alert(id.substring(7)); });
La siguiente es toda la información compartida por el editor sobre cómo recorrer las propiedades personalizadas de los tags, espero que sea de ayuda y esperamos que todos nos apoyen en el tutorial de grito.