Javascript 如何在jQuery中传递html表中的数据块
我喜欢htmlJavascript 如何在jQuery中传递html表中的数据块,javascript,jquery,ajax,Javascript,Jquery,Ajax,我喜欢html <table id="library_info_tbl"> <thead> <th>Call No.</th> <th>Book</th> <th>Accession No.</th> <th>Status</th> </thead> <tbody> <tr&g
<table id="library_info_tbl">
<thead>
<th>Call No.</th>
<th>Book</th>
<th>Accession No.</th>
<th>Status</th>
</thead>
<tbody>
<tr><td>12<td><td>ffyuyudf</td><td>61</td><td>Lost</td></tr>
<tr><td>12<td><td>ffyuyudf</td><td>62</td>Damaged</tr>
<tr><td>12<td><td>ffyuyudf</td><td>63</td>Damaged</tr>
<tr><td>13<td><td>abcdef</td><td>72</td>Lost</tr>
<tr><td>13<td><td>abcdef</td><td>73</td>Lost</tr>
...
</tbody>
</table>
用于实现statusarray和CallNotUse,以便在ajax调用中传递它们。基本上我希望代码应该像第一个一样工作,它应该检查表中类似的呼叫号码,例如在上表中
它应该首先基于callno 12进行提取,innerarray或statusarray应该包含如下数据
status: Lost,
accessionno: 61
status: Damaged,
accessionno: 62
status: Damaged,
accessionno: 63
callnotouse = 12
这些数据应该传递给ajax调用(将保存在数据库中)。之后,在表的同一个循环中,应该使用callno 13
status: Lost,
accessionno: 72
status: Lost,
accessionno: 73
callnotouse = 13
然后它应该被传递给ajax调用等等。基本上,我无法在类似callno的基础上调整上述代码。工作代码
var libraryInfos = [];
$("#library_info_tbl tbody tr").each(function(){
var tds = $("td", this);
var callNo = tds.first().html();
if(typeof libraryInfos[callNo] == 'undefined'){
libraryInfos[callNo] = [];
}
libraryInfos[callNo].push({
status: $(tds[4]).html(),
accessionNo: parseInt($(tds[3]).html())
});
});
$.each(libraryInfos, function(callNo, statusArr){
if(statusArr){
var reqData = { callno: callNo, statusarray: statusArr };
$.ajax({
url: 'index.php?action=savestatus',
type: 'POST',
dataType: 'JSON',
data: reqData
});
console.log(reqData);
}
});
演示:呼叫号码是否已排序?
var libraryInfos = [];
$("#library_info_tbl tbody tr").each(function(){
var tds = $("td", this);
var callNo = tds.first().html();
if(typeof libraryInfos[callNo] == 'undefined'){
libraryInfos[callNo] = [];
}
libraryInfos[callNo].push({
status: $(tds[4]).html(),
accessionNo: parseInt($(tds[3]).html())
});
});
$.each(libraryInfos, function(callNo, statusArr){
if(statusArr){
var reqData = { callno: callNo, statusarray: statusArr };
$.ajax({
url: 'index.php?action=savestatus',
type: 'POST',
dataType: 'JSON',
data: reqData
});
console.log(reqData);
}
});