var $singleMember = '<a class="singleMember"><img class="avatar"><p class="username"></p></a>';
$singleMember.attr('href',member.link);
$singleMember.children('.avatar').attr('src',member.avatar);
$singleMember.children('.username').html(member.name);
为什么抛出&#34; undefined不是函数&#34;?
答案 0 :(得分:1)
var $singleMember
只是一个字符串,因此.attr()
和.children()
无效(因此您看到错误)
将其切换为:
var singleMember = '<a class="singleMember"><img class="avatar"><p class="username"></p></a>';
var $singleMember = $(singleMember);
$singleMember.attr('href',member.link);
$singleMember.children('.avatar').attr('src',member.avatar);
$singleMember.children('.username').html(member.name);