gpt4 book ai didi

javascript - 当表只有一行时 tableToJson 不起作用

转载 作者:行者123 更新时间:2023-11-28 18:19:27 25 4
gpt4 key购买 nike

我正在使用 here 中的 tableToJson

我有以下模式窗口:

<div class="modal fade" id="myModalShopOrder" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Add Batch</h4>
</div>
<div class="modal-body">
<label class="control-label">Designation:</label>
<div id='complaintProgress' style="position: relative;">
<input type="text" class="form-control" name="DesignationShopOrder" id="DesignationShopOrder">
</div><br>

<div class="well">
<table class="table table-hover table-striped table-responsive table-bordered" id="shopOrderTable" >
<thead>
<tr>
<th data-override="ShopOrderDes">Designation</th>
</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="button" onclick="addShopOrder();" class="btn btn-success">Submit</button>
</div>
</form>
</div>
</div>
</div>

我正在运行脚本以将项目添加到表中:

<script>
function addShopOrder(){
var designation = document.getElementById('DesignationShopOrder').value;
var table = document.getElementById("shopOrderTable").getElementsByTagName('tbody')[0];
var row = table.insertRow(-1);
row.hidden = false;
var cell1 = row.insertCell(0);
cell1.innerHTML = designation;

var shopOrders = $('#shopOrderTable').tableToJSON();
shopOrders.pop();
var infoRec = new Array();
infoRec = JSON.stringify(shopOrders);
document.getElementById('shopOrderSender').value = infoRec;
}

</script>

我点击按钮添加,我的tableToJson数组是空的!如果我点击两次,我就会得到带有数据的数组!

为什么我需要点击两次?如果我的表中有一行,我也想转换它!红色矩形内有带有 Firebug 细节的图像! No Data after first click

With one element after second click

提前致谢

最佳答案

可能是由于“shopOrders.pop();”您正在删除最后一项,如果您只有一项,则将其删除

关于javascript - 当表只有一行时 tableToJson 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40136451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com