Jquery sortable('serialize')

前端 未结 6 1550
遥遥无期
遥遥无期 2021-02-01 08:57

Is it possible to get the serialized list of items from a UL in jquery by calling the serialize method directly instead of using a callback? The code snippet:

va         


        
6条回答
  •  醉酒成梦
    2021-02-01 09:44

    var formStr = $('#container').serialize()

    Added: That will work for form elements. You could also roll your own serialize like so:

    function serializeList(container)
    {
      var str = ''
      var n = 0
      var els = container.find('li')
      for (var i = 0; i < els.length; ++i) {
        var el = els[i]
        var p = el.id.lastIndexOf('_')
        if (p != -1) {
          if (str != '') str = str + '&'
          str = str + el.id.substring(0, p) + '[]=' + (n + 1)
          ++n
        }
      }
      return str
    }
    
    alert(serializeList($('#container')))
    

提交回复
热议问题