只是想知道是否有任何使用过JQuery或twitch的人能在这方面有所帮助。基本上,我试图获得一个用户名,但我不想要点击一个按钮或显示在一个输入框。
下面是API示例中的代码:
$('#get-name button').click(function() {
Twitch.api({method: 'user'}, function(error, user) {
$('#get-name input').val(user.display_name);
});
})
因此,有人知道我如何获得用户名而不显示在输入框中,或必须单击一个按钮来显示他们的用户名。
发布于 2015-04-19 11:19:08
您只需要像代码示例中那样调用Twitch.api
,但不需要担心在单击事件处理程序中这样做。
Twitch.api({method: 'user'}, function(error, user) {
// this code runs after the Twitch API returns you the user data.
// whatever you want to do with the username goes in here.
// for example:
console.log(user.display_name);
});
假设在HTML页面中的某个位置,您可以像您说的那样显示用户名:
<div class="greeting">
Welcome, <span class="username"></span>
</div>
然后你可以用
Twitch.api({method: 'user'}, function(error, user) {
$('.greeting .username').text(user.display_name);
});
将用户名填充到<span>
中。
https://stackoverflow.com/questions/29734601
复制相似问题