【发布时间】:2019-07-18 08:58:25
【问题描述】:
我正在尝试创建一个数组,但数据返回为空,它似乎没有工作,任何帮助将不胜感激。我已经更新并添加了 html。感谢大家的耐心。
当我的结果产生时,我仍然得到 [object Array]: []。
<table class="table table-bordered table-framed" id="seconDTable" style="display:block;" i>
<tbody id="secondtbody">
<tr name="myRow">
<td style="width: 100%;">
<input type="text" name="ParentTitle" value="book1">
<select id="ddlPageCount" style=" width: 35px; padding - top: 1px; height: 20px; font - size: 14px; color: #555555; vertical - align: left; background - color: #ffffff;1px solid #cccccc;border - radius: 1px; ">
@for (int i = 1; i < 10 + 1; i++)
{
<option value="@i">
@i
</option>
}
</select>
</td>
</tr>
<tr name="myRow">
<td style="width: 100%;">
<input type="text" name="ParentTitle" value="book2">
<select id="ddlPageCount" style=" width: 35px; padding - top: 1px; height: 20px; font - size: 14px; color: #555555; vertical - align: left; background - color: #ffffff;1px solid #cccccc;border - radius: 1px; ">
@for (int i = 1; i < 10 + 1; i++)
{
<option value="@i">
@i
</option>
}
</select>
</td>
</tr>
</tr>
}
}
</tbody>
</table>
var rows = document.getElementById("seconDTable").getElementsByTagName("myRow").length;
var data = [];
$("table tbody tr").each(function () {
var textval = $(this).find("td").find("input[type=text][name=ParentTitle]").val();
var ddlval = $(this).find("td").find("select option:selected").val();
for (var i = 0; i < rows ; i++) {
data.push{[
"Title": textval,
"PageNumber": ddlval
]};
}
console.log(data);
})
【问题讨论】:
-
“似乎不起作用”是什么意思?
-
标题:null 和 pageNumber:0
-
请提供足够的信息以便我们复制问题,最好是minimal reproducible example。
mynumber是什么?mynumber来自哪里?如果有的话,你会得到什么控制台错误? -
对不起,... var rows = document.getElementById(myTable).getElementsByTagName("myRow").length;
-
你没有给
data[i]分配任何东西。
标签: javascript