没有表格序列化? [英] serialize without a form?

查看:85
本文介绍了没有表格序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在用html对象(而不是表单)在html页面上打开(添加类.active)和关闭对象".每次单击时,我都希望它创建一个带有.active类的项目数组,但似乎无法获得任何结果?!

Hello all i'm turning objects "on (adding the class .active) and off" on a html page with html objects, not forms. And on every click i want it to create an array of the items with the class .active but i can't seem to get any results?!

这是朝正确的方向吗?

var data = $('li.tagToggle.active').serializeArray();
// li id format is 'id_0001' 
alert(data)
$.post("/scripts/php/process.php",{ 
         'data[]': data,
         funcName : 'tagResults',
         tagResults : '1'
}) 

保留警报并清空窗口,但是当我在窗体上使用它时,它将捕获所有带有.active类的对象

keeps alerting and empty window but when i use this on a form it grabs all the objects with the class .active

欢迎任何指针!

推荐答案

确定-可以正常使用,但不如serialize()整洁

ok - got this to work but its nots as neat as serialize()

function getTags(){

    var data = [];

    $('li.tagToggle.active').each(function(){
        var me = $(this);
        var id = me.attr("id").split('_');
        data.push(id[1])

    });

    $.post("/scripts/php/process.php",{ 
         'data': data,
         funcName : 'tagResults',
         tagResults : '1'
    }) 

}

认为有更好的方法吗?

这篇关于没有表格序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆