我正在寻找一种更好的方法将多个事件绑定到jQuery中的单个元素.我试图避免编写多个$(元素).bind('event',...)或$(element).event(...)语句.
码
// old way
var textbox = $('input');
$(textbox).focus(function() { ... }
$(textbox).blur(function() { ... }
// new way
$(textbox).extend({
focus: function() {
...
},
blur: function() {
....
}
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,这种实现不起作用.有人有更好的建议吗?谢谢.
一旦用户登录并授权我的应用程序代表他/她发布,我如何看待Facebook商家页面?到目前为止,这是我的代码:
window.fbAsyncInit = function() {
FB.init({ appId: 'MY_APP_ID',
status: true,
cookie: true,
xfbml: true,
oauth: true});
document.getElementById('fb-auth').addEventListener('click', function() {
FB.login(function(response){
if(response.authResponse){ // user has authorized app
FB.api('/me/likes/BUS_PAGE_ID', function(response){
if(response.data.length>0) {
// user has liked the page
} else {
// like the page for the user
}
});
}
}, {scope:'publish_actions, user_likes'});
}, false);
};
Run Code Online (Sandbox Code Playgroud)
代码正在工作,它授权应用程序,我可以看到用户喜欢FB.api(...)if(response.data.length> 0)的业务页面.我应该为用户的页面添加什么内容,以便我的应用程序可以像特定的商业页面一样添加到用户喜欢的页面?谢谢.