需求:页面动态添加的html元素(如div),保存时组装div中的数据为一个json对象。

思路:遍历每个div,再遍历div中每个输入元素,把所有先把数据放到一个对象中,再添加进数组,Json.stringfy()序列化。

简单效果图:

点击加号“+”,可以动态添加。

function getCurrentCustomePrice() {
var cuspricelist = new Array();
_.map($("#tabLinePriceType .baojia"), function (n) {
var comment = {};
$(n).find("input").each(function () {
switch ($(this).attr("type")) {
//自定义报价类型
case "hidden":
comment.custypeid = $(this).val();
break;
case "checkbox":
if ($(this).val() == "0" && $(this).is(":checked")) {
comment.manprice = 1;
break;
}
else if ($(this).val() == "1" && $(this).is(":checked")) {
comment.childprice = 1;
break;
}
break;
case "text":
switch ($(this).attr("name").substring($(this).attr("name").lastIndexOf('.') + 1, $(this).attr("name").length)) {
case "price": //成人同行价
comment.price = $(this).val(); break;
case "pricechild": //儿童同行价
comment.pricechild = $(this).val(); break;
case "mprice": //成人市场价
comment.mprice = $(this).val(); break;
case "mpricechild": //儿童市场价
comment.mpricechild = $(this).val(); break;
case "sprice"://网上优惠价
comment.sprice = $(this).val(); break;
case "spricechild": //儿童网上优惠价
comment.spricechild = $(this).val(); break;
}
break;
}
});
cuspricelist.push(comment);  //加入数组
})
return cuspricelist;
}

  

最新文章

  1. centos7最小安装后常常需要添加的命令
  2. Sharif University CTF 2016 -- Android App
  3. 组合数取模Lucas定理及快速幂取模
  4. java.lang.reflect.Field
  5. CSS - 如何实现强制不换行、自动换行、强制换行 以及 chrom默认焦点 IE下 Input 默认出现叉
  6. JS function的参数问题
  7. NuGet在2015中的使用
  8. 应用git(SSH设置)
  9. 【转】unity3d 各种优化综合
  10. yate.conf
  11. [Full-stack] 快速上手开发 - React
  12. Pick定理、欧拉公式和圆的反演
  13. linux/Centos下查看和修改网卡Mac地址(ifconfig命令)
  14. 把git上面的scala工程转为eclipse工程
  15. R语言绘图时的边界碰撞问题
  16. How far away ?(DFS)
  17. (windows下的)Apache无法启动解决 the requested operation has failed
  18. T1,T2,T3 三个线程顺序执行
  19. RecyclerView 数据刷新的几种方式 局部刷新 notify MD
  20. 3、激活层(Activiation Layers)及参数

热门文章

  1. AI GMM
  2. 页面跳转时,url 传大数据的参数不全的问题+序列化对象
  3. mybatis 使用resultMap实现表间关联
  4. Promise学习笔记
  5. C#、Java和JS实现SHA256+BASE64加密总结
  6. python学习日记(内置函数)
  7. tmux 使用说明
  8. jenkins在windows及linux环境下安装
  9. AGC027B Garbage Collector
  10. 三步解决fiddler升级后https无法通过证书验证问题