knockoutjs get element id through click event

前端 未结 2 1216
闹比i
闹比i 2021-02-12 10:50

I\'m using knockoutjs and I currently have something in my view that looks like this:



        
2条回答
  •  终归单人心
    2021-02-12 11:21

    You actually can get access to the event object via a KO click handler.

    
    
    var ViewModel = function() {
        this.log = function(data, event) {
            console.log("you clicked " + event.target.id);
        }
    };
    ko.applyBindings(new ViewModel());
    

    http://jsfiddle.net/madcapnmckay/e8JPT/

    Hope this helps.

提交回复
热议问题