【问题标题】:unable to fire checkbox event in jquery Mobile backbone无法在 jquery Mobile 主干中触发复选框事件
【发布时间】:2013-02-25 11:04:01
【问题描述】:

我正在使用 jquery Mobile 和 Backbone 开发应用程序。 click .check : toggleDone 事件未被触发。我不知道原因。请 帮助。

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>

【问题讨论】:

  • 尝试使用append 而不是html。阅读本文了解一些背景知识:tbranyen.com/post/missing-jquery-events-while-rendering
  • No append 也没有帮助。我认为,视图的事件没有正确绑定。虽然我无法弄清楚确切的原因。我正在使用 trigger('create') 和 append 来维护我的 jqueryMobile 样式。
  • 我将&lt;input type = "checkbox"&gt; 包裹在&lt;button&gt; 周围并添加事件"click .btn_check" : "toggleDone", 现在我可以使用该事件了。我想知道为什么它对复选框的行为很奇怪

标签: jquery-mobile backbone.js requirejs


【解决方案1】:

你不应该使用click——移动版Safari至少要等待300毫秒来触发点击事件,因为它试图决定触发clickdblclick

您应该尝试收听touchend

(Spine specifically has info 周围不使用click

【讨论】:

  • 感谢分享知识。听起来我也应该记住一个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-11
  • 2023-04-04
  • 1970-01-01
  • 2010-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多