这是我的代码:
$.fn.extend({
del: function() {
}
})
var ds = $(".d");
ds.del(ds[0])
console.log(ds.length)
我希望从jquery childs实现jquery.del到del子,但不能更改html,如何实现它?
更新
我可以实现var matchDs = ds.del(ds [0]),但我希望从原始jquery对象中获取del子元素的方法
答案 0 :(得分:0)
我发现jquery对象有#splice func,所以我可以使用以下代码:
$.fn.extend({
del: function (e) {
for (var i = 0; i < this.length; i++) {
if (this[i] == e) {
this.splice(i, 1)
}
}
}
})
var ds = $(".d");
ds.del(ds[0])
console.log(ds.length)