一个获取第n个元素节点的函数,现在只能通过html标签获取元素,功能还不完善
演示:html
- 1
- 2
- 3
- 4
- 5
test
js:
function nth(parent,ele,num){
var _ele=Array.prototype.slice.call(parent.childNodes),eleArray=[];
//将父节点的子节点转换成数组_ele;eleArray为只储存元素节点的数组
for(var i= 0,len=_ele.length;i
一个获取第n个元素节点的函数,现在只能通过html标签获取元素,功能还不完善
演示:html
test
js:
function nth(parent,ele,num){
var _ele=Array.prototype.slice.call(parent.childNodes),eleArray=[];
//将父节点的子节点转换成数组_ele;eleArray为只储存元素节点的数组
for(var i= 0,len=_ele.length;i