0

バックボーンビューに次の設定があります。

var SomeView;

SomeView = Backbone.View.extend({
    initialize: function() { this.render(); },
    render: function() { // render form },
    events: {
        "keydown form.registration input": "checkInput"
    },
    checkInput: function(e) {
        console.log(e);
        // this doesn't work but I am searching for such a function
        var attr = e.getAttributeWhichTriggeredEvent;
        $(attr).val();
        // validate...
    } 
});

ご覧のとおり、たとえば入力値を使用できるように、イベントをトリガーした要素のセレクターを取得したいと思います。

Chromiumのコンソールを調べたところ、イベントオブジェクトにいくつかの(現在の)ターゲット属性が見つかりました。残念ながら、それらには要素を識別するために使用できるものは何も含まれていませんが、おそらく私は十分に見えませんでした。

では、どうすればこれを行うことができますか?

4

2 に答える 2

1

I think you want..

$(e.target).val()
于 2012-07-12T06:48:55.080 に答える
1

DOM Event objects have a type that reflects the type of event that dispatched them (e.g. click, mousedown, etc.). They also have properties for target and currentTarget that reference DOM elements related to the event, one of those may suit.

Note that older IE doesn't support event.target but has event.srcElement instead.

于 2012-07-12T06:49:54.643 に答える