鍍金池/ 問(wèn)答/HTML/ 在游覽器控制臺(tái)copy的總是最后一個(gè)的數(shù)據(jù)

在游覽器控制臺(tái)copy的總是最后一個(gè)的數(shù)據(jù)

var ListTables = document.getElementsByClassName("listTable")[0];
var opinions = [];
var calls = [];
for(var i = 0, len = ListTables.rows.length; i < len; i++){

if(i == 0){
    var name  =  ListTables.rows[i].cells[0].innerHTML.replace(" - 意見建議", "");
} else{
    var opinion = ListTables.rows[i].cells[0].firstChild.innerHTML;
    opinions.push(opinion);
    var call = ListTables.rows[i].cells[0].lastChild.innerHTML;
    calls.push(call);
}

}
for(var j = 0, len = opinions.length; j < len; j++){

calls[j] = name + "    " + calls[j] + "    " + opinions[j] + "\n"
copy(calls[j]);

}

回答
編輯回答
老梗
var ListTables = document.getElementsByClassName("listTable")[0];
var opinions = [];
var calls = [];
for(var i = 0, len = ListTables.rows.length; i < len; i++){

    if(i == 0){
        var name  =  ListTables.rows[i].cells[0].innerHTML.replace(" - 意見建議", "");
    } else{
        var opinion = ListTables.rows[i].cells[0].firstChild.innerHTML;
        opinions.push(opinion);
        var call = ListTables.rows[i].cells[0].lastChild.innerHTML;
        calls.push(call);
    }
}
var str = "";
for(var j = 0, len = opinions.length; j < len; j++){
    str += name + "    " + calls[j] + "    " + opinions[j] + "\n";
}
copy(str);

//自動(dòng)跳轉(zhuǎn)
var next_page = location.href;
var next_page = next_page.split("=");
next_page[1] = parseInt(next_page[1]);
var num_add = next_page[1]+1;
var next_page_url = next_page[0] + "=" + num_add;
location.href = next_page_url;
2017年1月4日 01:56