自己用jQuery搞了个Table增加Row的东东,实现过程,有如下几个心得,记录在这里。
i. jQuery(table).append(jQuery(newRow)); jQuery API append方式的调用,通过这个append来给已有的Table新加行。
ii. var newRow = jQuery(hiddenRowEle).clone(true);这个clone方法是怎么封装document.getElementById(elemetId).cloneNode(true)的?jQuery做了这样的封装后弥补了cloneNode方法的哪些不足?
iii. jQuery的get(0)方法返回的是native的DOM元素?还是经过jQuery封装的?看jQuery的API,知道This(get(index)方法) allows you to extract the actual DOM element and operate on it directly without necessarily using jQuery functionality on it.
iv. 直接调用jQuery(parentRow).remove();,而非native的remove,依稀记得native的remove方法在遍历地remove时,会在类似ArrayList中remove(Object o)时的问题。
本文分享了使用jQuery操作Table元素的心得:利用append方法添加新行;探讨了clone方法相较于cloneNode的优势;解析get(0)方法返回类型;并讨论了remove方法的使用技巧。
1587

被折叠的 条评论
为什么被折叠?



