Comment puis-je analyser les attributs data- * avec JQuery? Est-ce que quelque chose comme $('a').attr('data-*').each(function(){...});
est possible? Y a-t-il une méthode simple?parse data- * with jquery
1
A
Répondre
0
Parlez-vous des attributs de données,
ce plugin metata jquery est vraiment bon
http://plugins.jquery.com/project/metadata
3
Je pense que vous essayez de faire quelque chose comme ceci:
$('a').filter(function() {
//if this function returns false, it will not be included in the set.
return $(this).data().length > 0;
}).each(function() {
//iterate over every matched DOM element
//and iterate over their data attribute:
$.each($(this).data(), function(key, value) {
//do something with key and value here...
});
});
0
Try this http://jsfiddle.net/6tv5y/1
<div id="mydiv" data-name="negative" data-from="stackoverflow"></div>
var mydata = $('#mydiv').data();
$.each(mydata ,function(i) {
alert(mydata[i]);
});
UPD: Notez qu'il n'est pris en charge que depuis jQuery 1.4.3.
Questions connexes
- 1. User matching with current data
- 2. Parse JSON dans jquery
- 3. jquery parse json
- 4. Trouble with JSON jQuery Méthode
- 5. Parse JSON dans jquery
- 6. paginaton dropdown with jquery
- 7. Jquery Slider With Fading
- 8. parse html chaîne avec jquery
- 9. XML Parse avec jQuery
- 10. Parse XML avec jQuery
- 11. Trouble with formulaire email jquery submitHandler
- 12. PHP: parse JSON de jQuery
- 13. Rails parse jQuery cite mal
- 14. jQuery: Templating data
- 15. jQuery data() retourne undefined
- 16. Jquery - each et data()
- 17. jQuery .data vs eventData
- 18. Jquery data() stockage
- 19. Trouble with annexant un formulaire dans jQuery
- 20. jQuery: Parse/HTML sans Manipulez scripts d'exécution
- 21. Ajax JSON Parse Erreur
- 22. Boucle jQuery via l'objet data()
- 23. Fonction jQuery data() dans GreaseMonkey
- 24. jQuery .data(): possible d'incrémenter (++ ou -)?
- 25. L'instruction 'with' de Python versus 'with .. as'
- 26. Equivalence de "With ... End With" dans C#?
- 27. dans IE, l'en-tête "X-Requested-With" de jquery devient "x-requested-with" (minuscule)
- 28. Parse complète page html avec jquery
- 29. Jquery-ajax parse XML et de RadioButton
- 30. contenu Parse comme XML, avec jQuery
Il existe une différence entre [HTML5 'data- *' attributes] (http://ejohn.org/blog/html-5-data-attributes/) et jQuery ['data()'] (http://api.jquery.com/data/) stockage; Je pense que le PO pose des questions sur le premier et vous répondez pour le dernier. – Phrogz
@Phrogz, http://cl.ly/313n2V430t19182M3Y1l –
Je suis corrigé! Merci pour la clarification. – Phrogz