【发布时间】:2016-09-19 01:57:10
【问题描述】:
我正在创建一个小型待办事项应用程序,遇到了一个问题,看起来警报消息在点击事件触发之前运行。看起来该事件根本没有注册。谁能告诉我为什么会这样?
(function() {
'use strict';
var MyTodo = {
init: function() {
this.cacheDom();
this.bindEvent();
this.addTask();
},
cacheDom: function() {
this.$title = $('#inpTitle');
this.$date = $('#inpDate');
this.$description = $('#inpDescription');
this.$addTaskBtn = $('#addTaskBtn');
this.$pending = $('#pending');
},
addTask: function() {
if (!this.$title.val()) {
alert('please enter title');
return;
}
var value = '<ul class="todo-task" id="todoList" draggable="true"><li><strong>' + this.$title.val() + '</strong></li>' +
'<li>' + this.$date.val() + '</li>' +
'<li>' + this.$description.val() + '</li></ul>';
this.$pending.append(value);
// empty inputs
this.$title.val('');
this.$date.val('');
this.$description.val('');
},
bindEvent: function() {
this.$addTaskBtn.on('click', this.addTask.bind(this));
}
};
MyTodo.init();
})();
【问题讨论】:
标签: javascript jquery angularjs node.js