문제

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