How do I convert the items of an LI into a json object using jquery?

前端 未结 3 1374
别那么骄傲
别那么骄傲 2021-02-04 13:59

If I have a list like the following:

  • Bob
  • Frank
3条回答
  •  佛祖请我去吃肉
    2021-02-04 14:18

    var items = [];
    
    $('ul.nameList').children().each(function() {
      var $this = $(this);
      var item = { id: $this.attr('value'), title: $this.html() };
      items.push(item);
    });
    

提交回复
热议问题