dongshiru5913 2011-07-23 01:34
浏览 463
已采纳

如何创建一个JSON(jQuery),发布一个完整的数组

I'm trying to create an event handler (jQuery) that will pick all elements of specific class, each unique ID value, post json array, loop through php, finally update view.

I have no problem with selecting one instance.

**Mostly looking how to create the array of id,value to pass for processing.

Thank You

  • 写回答

3条回答 默认 最新

  • douchang6770 2011-07-23 01:37
    关注

    You can do something like this (As a strting point):

    $('.class').each(function(){
     // do somthing with $(this)
    });
    

    Of course, if you post some more details, I can expand on this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • duanli6834 2011-07-23 21:41
    关注

    This snippet will give you an array of the ids of the elements with class myclass:

    var id_array = $.map($(".myclass"),function(el){return el.id;});
    

    You can then send the array to your server as JSON, or as a comma separated string, or any other way you want.

    评论
  • douhan8581 2011-07-24 11:05
    关注

    To get an array of all selected elements

    var elArray = $('.classToSelect').get();
    

    After this you may use

    $.each(elArray, function(el){
         var id = el.id;
         var value = el.value;
         //code goes here
    }
    

    A small plugin script from http://code.google.com/p/jquery-json/ is perfect for JSON encoding and decoding:

    var postdata = $.toJSON(elArray);
    

    generates a well formatted JSON string.

    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 C语言字符串不区分大小写字典排序相关问题
  • ¥15 关于#python#的问题:我希望通过逆向技术爬取1688搜索页下滑加载的数据
  • ¥15 学习C++过程中遇到的问题
  • ¥15 关于Linux的终端里,模拟实现一个带口令保护的屏保程序遇到的输入输出的问题!(语言-c语言)
  • ¥15 学习C++过程中遇到的问题
  • ¥15 请问,这个嵌入式Linux系统怎么分析,crc检验区域在哪
  • ¥15 二分类改为多分类问题
  • ¥15 Unity微信小游戏上调用ReadPixels()方法报错
  • ¥15 如何通过求后验分布求得样本中属于两种物种其中一种的概率?
  • ¥15 q从常量变成sin函数,怎么改写python代码?