谢谢阅读。我有一个想要原型的 jQuery 函数。该函数只是将隐藏/显示函数绑定到复选框。每个复选框对应于要隐藏的不同元素。我一直在控制台日志记录,并且正在创建对象;控制台上没有其他错误。此功能有效:
$("input[name='fcrBox']").bind('change', function(){
if( $(this).is(':checked')){
$("#result").show();
} else {
$("#result").hide();
}
});
但这不会:
function HideShow(elem, affected) {
this.elem = elem;
this.affected = affected;
}
var fcrBox = new HideShow('input[name="fcrBox"]', '#result');
var sc = new HideShow('input[name="sc"]', '#MQSresult');
console.log(fcrBox);
console.log(sc);
HideShow.prototype.binder = function(elem, affected){
$(elem).bind('change', function(){
if( $(this).is(':checked')){
$(affected).show();
} else {
$(affected).hide();
}
});
}
fcrBox.binder();
sc.binder();
谢谢!任何输入将不胜感激。