I开发者_如何学Pythonm setting index numbers on a html lists item $("li").data("index", someValue).
I don't know how to find a specific li based on this index value. Ive searched on here and Ive seen a few posts re: html5 data attributes but Im using JQuerys .data function to append data to the dom and not to the html itself.
Can anyone help?
Using a filter.
 $('selector').filter( function() { return $.data(this,'foo') == 'desired'; } )
              ...
I usually set an id to the li that help retrieve it easily (if I understood your problem). Something like :
<ul>
   <li id="my-list-id-1">...</li>
   <li id="my-list-id-2">...</li>
   <li id="my-list-id-3">...</li>
   <li id="my-list-id-4">...</li>
</ul>
And then, to find the specific li, it's just as easy as :
$('li#my-list-id-' + index)
Hope this helps.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论