为什么console.log(product.bindEvent())是undefind 怎么写才能调这里面的事件方法呢?
functionProduct(){this.img='';this.discount='';this.description='';this.oldPrice='';t...
function Product(){
this.img='';
this.discount='';
this.description='';
this.oldPrice='';
this.groupPrice='';
this.date='';
}
Product.prototype={
bindDom:function(){
var str='';
str+='<dl>';
str+='<dt><a><img src="'+this.img+'" width="384" height="225" /></a></dt>';
str+='<dd>';
str+='<span><a><em>'+this.discount+'</em>'+this.description+'</a></span>';
str+='</dd>';
str+=' <dd class="price">';
str+='<em>'+this.oldPrice+'</em>';
str+=' <del>'+this.groupPrice+'</del>';
str+='<i>'+this.date+'</i>';
str+=' </dd>';
str+='</dl>';
return str;
},
bindEvent:function(){
$('.conBottomT>dl').mouseenter(function(){
$(this).css('borderColor','red');
})
}
};
var products=[
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'500',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'}
];
var str='';
for(var i=0;i<products.length;i++){
var product=new Product();
product.img=products[i].img;
product.discount=products[i].discount;
product.description=products[i].description;
product.oldPrice=products[i].oldPrice;
product.groupPrice=products[i].groupPrice;
product.date=products[i].date;
str+=product.bindDom();
}
$('#container').html(str);
console.log(product.bindEvent()); 展开
this.img='';
this.discount='';
this.description='';
this.oldPrice='';
this.groupPrice='';
this.date='';
}
Product.prototype={
bindDom:function(){
var str='';
str+='<dl>';
str+='<dt><a><img src="'+this.img+'" width="384" height="225" /></a></dt>';
str+='<dd>';
str+='<span><a><em>'+this.discount+'</em>'+this.description+'</a></span>';
str+='</dd>';
str+=' <dd class="price">';
str+='<em>'+this.oldPrice+'</em>';
str+=' <del>'+this.groupPrice+'</del>';
str+='<i>'+this.date+'</i>';
str+=' </dd>';
str+='</dl>';
return str;
},
bindEvent:function(){
$('.conBottomT>dl').mouseenter(function(){
$(this).css('borderColor','red');
})
}
};
var products=[
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'500',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天香豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'},
{img:'img/boutque08_r2_c2.jpg',discount:'5.5',description:'天豆蔻',oldPrice:'500',groupPrice:'400',date:'2015/12/3'}
];
var str='';
for(var i=0;i<products.length;i++){
var product=new Product();
product.img=products[i].img;
product.discount=products[i].discount;
product.description=products[i].description;
product.oldPrice=products[i].oldPrice;
product.groupPrice=products[i].groupPrice;
product.date=products[i].date;
str+=product.bindDom();
}
$('#container').html(str);
console.log(product.bindEvent()); 展开
展开全部
product.bindEvent()
你这个应该调用成功了,但是你
bindEvent:function(){
$('.conBottomT>dl').mouseenter(function(){
$(this).css('borderColor','red');
})
}
没写返回值啊,所以console.log(product.bindEvent())返回的是undefind
你试试bindEvent里加个return
你这个应该调用成功了,但是你
bindEvent:function(){
$('.conBottomT>dl').mouseenter(function(){
$(this).css('borderColor','red');
})
}
没写返回值啊,所以console.log(product.bindEvent())返回的是undefind
你试试bindEvent里加个return
追问
是的 加了个 return $('.conBottomT>dl').mouseenter(function(){
$(this).css('borderColor','red');
}) 就可以了 感谢回答啊
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询