爲了更容易閱讀,我把所有東西放在initialize
函數下。 這裏有什麼不對嗎?警報被觸發,所以它不是條件。 我有隱藏的共享操作,並希望在桌面上懸停顯示它們,並在懸停不可能的情況下點擊移動設備。 我在這裏錯過了什麼嗎? console.log()
不會引發任何錯誤。有條件地在Backbone - 手機或臺式機上綁定事件
App.Views.Title = Backbone.View.extend({
initialize:function(){
_.bindAll(this,"stickToTop");
this.template = _.template($("#title").html());
this.render();
$(window).scroll(this.stickToTop);
var isMobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);
var share = this.$(".share");
if(isMobile){
// alert('mobile')
share.on('click' , this.shareMobile , this);
}else{
// alert('not mobile')
share.on('hover' , this.shareDesktop , this);
}
},
...
,我想'窗口phone'從你丟失的用戶代理正則表達式http://stackoverflow.com/a/9926619/429521 – 2013-04-10 19:54:40