Stack.

I'm using Backbone's event map in my View.

JS:

events: {
    "click .edit-info-button": "pullEdits"
},
pullEdits: function(e){
    // Get the value of the button clicked
    e.preventDefault();
    $(".edit-info-button").click(function(){parseEdits(this.value);});
}

HTML:

<button class="button edit-info-button" value="edit address">EDIT</button>

When edit-info-button is a class, the event listener does not work. pullEdits() never fires.

When I change edit-info-button into an id ("click #edit-info-button", "button id='edit-info-button', etc.) pullEdit() and all functions after it run successfully.

The issue is, the page I'm working on needs multiple edit buttons and I'd like to give them the same class and pull the value instead of giving them all unique ids.

Am I missing something? Thanks.

有帮助吗?

解决方案

Try this instead.

...
events: {
    "click .edit-info-button": "pullEdits"
},
pullEdits: function(e){
    var val = $(e.target).attr('value')
    return parseEdits( val );
}
...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top