【发布时间】:2013-12-24 22:07:43
【问题描述】:
我有一组复选框,我想根据它们的类为它们创建一个自定义方法。
var checkboxs = $("input[type=checkbox]");
checkboxs.each(function(){
if($(this).hasClass("class1")){
$(this).method1 = function(){
$(this).removeAttr("checked");
return $(this);
}
}
if($(this).hasClass("class2")){
$(this).method1 = function(){
$(this).parents("tr").next().hide();
$(this).removeAttr("checked");
return $(this);
}
}
});
如果,我想这样做:
checkboxs.each(function(){
$(this).method1();
});
它告诉我没有 method1 方法。为什么这不起作用?
【问题讨论】:
标签: jquery object methods each