使用jQuery将table标签中的数据封装成json串

    xiaoxiao2021-03-25  130

    function getJson() { var jsonStr = "{\"scientificProject\":["; $('#tableId tbody').find('tr').each(function () { //tableId 是table表格的id jsonStr += "{"; $(this).find('td').each(function () { $(this).find('input').each(function () { //获取td中input的值 if($(this).attr("myName")) { //myName是input标签的一个自定义属性 jsonStr += "\""+$(this).attr("myName")+"\":\""+$(this).val()+"\","; } }) }) jsonStr = jsonStr.substring(0,jsonStr.length - 1); jsonStr += "},"; }) jsonStr = jsonStr.substring(0,jsonStr.length - 1); jsonStr += "]}"; return jsonStr; }
    转载请注明原文地址: https://ju.6miu.com/read-18155.html

    最新回复(0)