在<a> hyperlink with Backbone&#39;s Events function</a>上捕获点击事件

时间:2012-11-23 21:14:07

标签: javascript html backbone.js hyperlink click

我最近从使用两个按钮切换到使用骨干模型中的链接下拉列表。

以前,此代码捕获了这些按钮点击次数:

events: {
        "click #expense-delete-button": "deleteRow",
        "click #expense-copy-button": "copyRow",
    },

这很好,但是现在我已经将我的HTML更改为:

<div class ="expense-action-icons btn-group">
    <button class="btn btn-mini dropdown-toggle" data-toggle="dropdown">
        <i class="icon-cog"></i>
    </button>
    <ul class="dropdown-menu pull-right">
        <li>
            <a href="#" id="expense-copy-button">
                <img src="../Images/copy.png"/>
                Copy Entry
            </a>
        </li>
        <li>
            <a href="#" id="expense-delete-button">
                <i class="icon-trash"></i>
                Delete Entry
            </a>
        </li>
    </ul>
</div>       

未捕获点击次数。我也试过了onclick,但这没效果。

1 个答案:

答案 0 :(得分:3)

您必须在视图中创建该功能。

    events: {
        "click #expense-delete-button": "deleteRow",
        "click #expense-copy-button": "copyRow",
    },

    deleteRow:function(e){
        e.preventDefault();
        //Element clicked on
        var target =  $(e.currentTarget);
        console.log('whatever you want');
    },

    copyRow:function(e){
        //Element clicked on
        var target =  $(e.currentTarget);

        console.log('copy your row');
    },

    initialize:function(){
        //view code....
    }