2013-02-25 51 views
2

我正在開發一個使用jQuery Mobile和Backbone的應用程序。 click .check : toggleDone事件未被解僱。我不知道原因。請致電 幫忙。jquery中無法觸發複選框事件Mobile backbone

var requestItemView = Backbone.View.extend({ 
tagName: "label", 
template : $("#requestItemTemplate").html(), 
events : { 
    "click .check" : "toggleDone", 
}, 
toggleDone: function() { 
    console.log("clcik"); 
    this.model.toggle(); 
}, 
initialize: function() { 
    console.log("requestItemInit"); 
}, 
render: function() { 
    var tmpl = _.template(this.template); 
    $(this.el).html(tmpl(this.model.toJSON()));  
    return this; 
}}); 

這是我相同的觀點

<script type='text/template' id='requestItemTemplate'> 
<label> 
    <input type="checkbox" class = "check" 
    <%= done ? 'checked="checked"' : '' %> data-theme="e"> 
    <%= requestorName%> :: <%=requestorEmailId%> : <%= requestorContactNo%> 
    </input> 
</label> 
</script> 
+0

嘗試使用'append',而不是'html'。閱讀這一點的背景:http://tbranyen.com/post/missing-jquery-events-while-rendering – neebz 2013-02-25 11:10:01

+0

沒有'append'也沒有幫助。 我認爲,視圖的事件沒有被正確綁定。雖然我無法確切的原因。 我使用trigger('create')和'append'來維護我的jqueryMobile樣式。 – 2013-02-25 12:03:34

+0

我圍繞一個'

回答

1

,則不應使用click模板 - 在至少300ms以內等待消防click事件,因爲它試圖決定以解僱移動Safari瀏覽器clickdblclick

您應該嘗試聆聽touchend

(脊柱specifically has info周圍不使用click

+0

Thx分享知識。聽起來像是我應該牢記的一個問題。 – 2013-08-07 06:44:05