如果我使用搜索框搜索“ HAlexer ”,图片将会是
“http://site/avatar/200/NICKNAME”(其中NICKNAME将为“HAlexer”)
JavaScript代码:
$(document).ready(function() {
var SITE_URL = "http://site/";
var JSON = SITE_URL+"json/";
var interval_BeautifulCounter;
var counterRequest;
$('#user-search-butt').click(function() {
var username = $('#user-search').val();
if (username !== '') {
DisplayUsersInfo(username);
} else {
ShowAlert('Username cannot be empty!', 'danger');
}
});
function DisplayUsersInfo(username) {{
// Title
$('#modal-username-title').html(data.username);
// Avatar
$('#modal-img-avatar').attr('src', SITE_URL+'avatar/256/'+data.username);
$('#modal-img-avatar').attr('alt', data.username+' avatar');
$('#modal-img-avatar').attr('title', data.username+' avatar');
$('#modal-input-avatar').val(SITE_URL+'avatar/'+data.username);
// Skin
$('#modal-img-skin').attr('src', SITE_URL+'skin/256/'+data.username);
$('#modal-img-skin').attr('alt', data.username+' skin');
$('#modal-img-skin').attr('title', data.username+' skin');
$('#modal-input-skin').val(SITE_URL+'skin/'+data.username);
// Skin Back
$('#modal-img-skin-back').attr('src', SITE_URL+'skin-back/256/'+data.username);
$('#modal-img-skin-back').attr('alt', data.username+' skin back');
$('#modal-img-skin-back').attr('title', data.username+' skin back');
$('#modal-input-skin-back').val(SITE_URL+'skin-back/'+data.username);
// buttons
$('#modal-btn-user').attr('href', SITE_URL+'user/'+data.username);
$('#modal-btn-download').attr('href', SITE_URL+'download/'+data.uuid);
$('#modal-btn-change').attr('href', 'http://www.minecraft.net/skin/remote.jsp?url='+SITE_URL+'skins/'+data.uuid+'.png');
$('#user-info-modal').modal('show');
}
}
});
} else {
ShowAlert('Alert!', 'danger');
}
}
return true;
}
});
答案 0 :(得分:1)
在DisplayUsersInfo
函数中,您不应该使用data.username
,而只能使用username
。
此外,由于您的输入字段的ID为#username
,我认为您的行
var username = $('#user-search').val();
应该是
var username = $('#username').val();
您的jQuery选择器$('#user-search')
似乎没有引用您发布的代码中的任何内容。