将Cookie数据从表存储到2D数组

时间:2017-03-12 13:23:17

标签: javascript arrays

我有一个html表,它接收字符串和int数据 - 我想在这个表上设置一个cookie,然后将数据存储到2d数组,这样我就可以用这些数据重新填充表。到目前为止,我有这个设置cookie,但我想用数组代替。

 function setCookie(cname, cvalue, exdays) {

    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+ d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function saveTable() {

    var data = '';

      for (var i = 0; i < table.rows.length; i++) {
        for (var j = 0; j < table.rows[i].cells.length; j++) {
           data += table.rows[i].cells[j].innerHTML + ",";
       }
     }
     data = table.rows.length + "," + table.rows[0].cells.length + "," + data.substring(0, data.length); // remove the last extra ","
      setCookie("marks", data, 60);
      alert("Cookie Saved");
}

0 个答案:

没有答案