简体   繁体   中英

Random (bullet) images for List Items in a UL?

I have a ul li sidebar generated from wordpress posts. The client has used different images for the bullet for each LI. Rather then adding a separate bullet manually, is there a way to do it that it chooses from a set of say 10 options?

was thinking Jquery function? Anyone ever done this?

THanks

Perhaps something like the following:

<style type="text/css">
/* Add the styles here, incrementing the number of each one as you go (then change
   the 3 in the jQuery addClass method so it corresponds with the number of options
   available */
li.bullet-0 { list-style-type: circle; }
li.bullet-1 { list-style-type: disc; }
li.bullet-2 { list-style-type: square; }
</style>
<Script type="text/javascript">
$(document).ready(){
  $('ul > li').each(function(i,e){
    $(this).addClass('bullet-'+(i%3)); // change 3 to number of styles that are above.
  });
});
</script>

jsFiddle link to show it being applied: http://www.jsfiddle.net/bradchristie/yxZ4m/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM