87,838
社区成员




LeftChat = function(userID,contentType,content){
this.content = content;
this.init();
};
LeftChat.prototype = {
init:function(){
this.contentDiv = '<div class="leftText voiceDiv"><audio src="' +
this.content+'"></audio></div>';
this.chat = ('<li id="chatTest">' +
'<div class="leftChat">' +
'<div class="leftImg imgPart"><img src="common/img/icon.jpg"></div>' +
this.contentDiv +
'<div class="clear"></div>' +
'</div>' +
'</li>');
},
show:function(){
$('#chatList').find('ul').append(this.chat);
console.log($('.voiceDiv',this.chat));
$($('.voiceDiv',this.chat)).unbind().on('click',function(){
this.playVoice();
}.bind(this));
},
playVoice:function(){
console.log($(this.chat).find('audio'));
//$(this.contentDiv).find('audio')[0].play();
}
};
new LeftChat('id','voice','common/mp3/5652.mp3').show();
new RightChat('efg','456').show();
new LeftChat('id','voice','common/mp3/testVoice.mp3').show();
$('.voiceDiv',this.chat);
$($('.voiceDiv',this.chat)).unbind().on('click',function(){
this.playVoice();
}.bind(this));
试试live或者在父元素上delegate.或者在添加div时bind('click')$('.voiceDiv',this.chat)
是什么意思。在你运行时this.chat指的是字符串还是dom element,还是jquery对象