issue with insertBefore()
issue with insertBefore()
我得到了一个小对象,它必须将新行追加到表..它在大多数情况下工作得很好,但如果有一个表在一些行(在"根"表)对象不追加到适当的表!
我一直在做一些调试,发现这一行都出错了。如果设置了DEBUG并且省略了insertBefore()行,则对象将追加到相应的表
var List = new function(){
this.append_row = function(row, tbl, index){
if(DEBUG){
index = -1;
}
if(index == 0){
row.prependTo(tbl);
}
else if(index > 0){
var elm = $('tr', tbl);
if(elm.length > index){
row.insertBefore(elm.eq(index)); // the issue is in this line
}
else{
row.appendTo(tbl);
}
}
else{
row.appendTo(tbl);
}
};
}
这是因为:
var elm = $('tr', tbl);
…相当于:
var elm = $(tbl).find('tr');
因此它将在任何嵌套的<table>
中定位所有嵌套的<tr>
元素。
你可以这样写:
var elm = $(tbl.rows); // if `tbl` is the DOM element
或:
var elm = $(tbl[0].rows); // if `tbl` is a jQuery object
现在elm
只引用tbl
的rows
,而不是任何嵌套的<table>
元素。
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Modify Javascript with C#
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- jQuery insertBefore error with Internet Explorer
- issue with insertBefore()