Safari 和 Chrome 中的行索引 -1 结果
当我尝试访问动态创建的表行时,为什么我在 Safari 和 Chrome 中得到行索引 -1 结果?
该行附加了 document.getElementById('tabl').appendChild(rowobject)
,然后获取 row Index 的值 -1。我能以某种方式解决这个问题吗?
Why I get Row Index -1 result in Safari and Chrome when I try to access a dynamic created table row?
The row is appended with document.getElementById('tabl').appendChild(rowobject)
and then gets the value of -1 to row Index. Can I fix this somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当引用表中的活动/选定行时,索引 -1 表示当前没有活动/选定行。当通过某个字段的内容搜索表的行索引时,搜索结果为-1表示没有找到该行。
这是因为表是基于 0 索引的 - 意味着第一行是第 0 行,第二行是第 1 行,等等。-1 明确指没有行/无效行。
When referencing the active/selected row in a table, an index of -1 means there is currently no active/selected row. When searching for the row index of a table by the content of some field, a search result of -1 means no such row was found.
This is because tables are 0 index based - meaning the first row is row 0, the second row is row 1, etc. -1 refers explicitly to no row / an invalid row.
当您创建表时,而不是:
write:
这会将新行追加到表末尾,但新行现在即使在 Chrome 和 Safari 中也将具有正确的索引。如果您想为其设置一些属性(例如 ID)或附加更多子项(例如
td
),则可以使用返回的对rowobject
的引用。祝你有美好的一天 :)
When you are creating the table, instead of:
write:
This will append a new row to the end of the table, but the new row will now have a correct index even in Chrome and Safari. You can then use returned reference to the
rowobject
if you want to set some properties to it, such as ID or to append further children such astd
.Have a great day :)