I want to remove the spaces on both sides of the matrix (split with tab), why only the last line is executed and meets the requirements

function takeout(th) {

var text2 = $("-sharpdata_matrix").val();//

var allcon2 = text2.split("\n");//

for (var i =0; i < allcon2.length; iPP) {//

a = allcon2[i].split("\t");  //tab

var ha=a.join("\t");//tab

// console.log(ha);

$(th).val($.trim(ha));
//
}
return true;//
}



textarea  
<textarea onblur = "takeout(this);" id="data_matrix" rows="20" cols="100" style=" height:218px;min-height:218px;width: 100%;margin-bottom: 20px;">ID Zygote 2_cell 4_cell 8_cell Morula ICM
Pou5f1 1 6 0.6 0.1 1 6
Sox2 2 5 0.5 0.2 2 6651
Gata2 3 4 0.4 0.3 3 46
cMyc 4 3 0.3 0.4 4 36
Tet1 5 2 0.2 0.5 5 25
Tet3 6 1 0.1 0.6 6 1</textarea>



$(th). Val ($.trim (ha)) here every time the contents of the textarea are emptied and replaced with the contents of the current loop, so the result is only the last record.

The

solution is to start by emptying the content, and then loop by adding to the original content each time, rather than directly setting

considering the performance problem, it is best to concatenate strings first in the loop, and then unify val ()

.
var text2 = $('-sharpdata_matrix').val();//

var allcon2 = text2.split("\n");//

$(th).val('');    // 

for (var i =0; i < allcon2.length; iPP) {//

a = allcon2[i].split('\t');  //tab

var ha=a.join("\t");//tab

// console.log(ha);

$(th).val($(th).val() + $.trim(ha) + '\n');
// 
//
}
return true;//
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3af26-2b79f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3af26-2b79f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?