假设我有以下 HTML 模板:
<script type="text/template" id="template">
<form>
<div class="form-group">
<input class="form-control" type="email" id="email" name="email">
</div>
<div class="form-group">
<input class="form-control tel" type="text" id="phone" name="phone">
</div>
// rest of the ui
</form>
</script>
<script>
// Backbone View
SomeForm = Backbone.View.extend({
template:$('#template').html(),
events:{
'input .tel':'telChanged'
},
telChanged:function(e){
var value = this.$('.tel').val();
console.log('tel changed, value = ',value);
},
render:function(){
this.$el.html(this.template());
// some example that uses
this.$('.tel').mask('9-999-999-999');
return this;
}
});
var view = new SomeForm();
$('#app').html(view.render().$el);
</script>
现在,每当用户.tel
输入输入时,该telChanged
方法都不会被触发,并且控制台不会打印任何内容!
谁能告诉我们是什么原因造成的,并在此先感谢您。