click event doesn't fire in an underscore temp

2019-09-11 19:43发布

问题:

Inside my list item view I want to react on click events which should be bound to each list item template elements. I've got a template with a collapsible content (jquery mobile) and inside the h1 tag the click events don't fire, but for the "send-btn" outside the h1 tag the click event works.

I also tried "button.delete-btn" or "h1 .delete-btn" but this doesn't work.

For some time "button.delete-btn" worked but since I moved to jqm 1.1.1 from jqm 1.1.0 it doesn't work anymore..

<script type="text/template" id="post">
    <div data-role="collapsible" data-theme="b" data-content-theme="b" data-collapsed="false">
        <h1>
            <button class="delete-btn" data-theme="b" data-inline="true">Delete</button>
            <p class="ui-li-aside ui-li-desc"><strong><%= time %></strong>, <%= date %></p>
        </h1>
    </div> 
    <div data-role="fieldcontain">
        <fieldset data-role="controlgroup" data-type="horizontal">
            <input class="my-input" type="text" />
            <button class="send-btn" data-inline="true" data-theme="b">Send</button>
        </fieldset>
    </div>
</script>

var PostView = Backbone.View.extend({ 
    template: _.template($("#post").html()),
    events: {
        "click .delete-btn": "delete",
        "click .send-btn": "send"
    },
 });