假设我有以下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
方法,并且不会向控制台打印任何内容!
任何人都可以告诉我们造成这种情况的原因并提前感谢您。