我是网络初学者。我的看法如下:
window.CreateAndEditContactView = Backbone.View.extend({
initialize: function() {
this.init(); // loads template
},
init: function() {
var popupWindow = $('body').append(".content"); // I used .content instead of template
var saveButton = popupWindow.find('#save_new_contact');
saveButton.click(function(){
var emailContact = popupWindow.find('#contact_email').val();
var nameContact = popupWindow.find('#contact_name').val();
console.log(emailContact + " : " + nameContact);
}
}
});
我的 html 看起来像这样:
<div class="content">
<div class="write_name">
<span class="name">Name</span>
<input id="contact_name" type="text"/>
<img class="avatar" src="/images/avatar2.jpg">
</div>
<div class="write_email">
<span class="name">e-mail</span>
<input id="contact_email" type="text"/>
</div>
<input type="submit" id="save_new_contact" value="Save"/>
</div>
控制台始终写入相同的值。我无法从中获得我的新价值<input id="contact_name" type="text"/>
。我究竟做错了什么?