我正在尝试扩展jQuery插件以添加自定义功能,元素具有ul并且具有多个li元素(li将由此插件本身添加),我试图点击li元素html
var Fileupload = function (element, options) {
this.$element = $(element)
this.$list = this.$element.find("ul li")
}
Fileupload.prototype = {
listen: function () {
$(this.$list).on('click',$.proxy(this.click,this)) // i guess error could be here
}
click: function(e){
this.$img = e.target;
var test = this.$img;
if($(test).attr("src"))
{
$(test).closest("li").append("<button class='btn btn-mini'>Remove</button>")
}
}
}
注意:我正在使用bootstrap fileupload插件,我想维护代码的结构,我不喜欢
.find("ul li").click(//my code here}