jQuery: how to access parent function “this” from inside anonymous function?

前端 未结 5 925
余生分开走
余生分开走 2020-12-28 16:07
...
$.fn.annotateEdit = function(image, note) {
    if (note) {
        this.note = note;
    } else {
        var newNote = new Object();
        newNote.id = \"new         


        
5条回答
  •  再見小時候
    2020-12-28 16:37

    Use $.proxy to bind it to a function...

       // Returns a function-------v
    form.find(':radio').change( $.proxy(function() {
    
        var vacancy = $(this).attr('value');
        mynote.vacancy = vacancy;
    
    }, this) );
    //   ^---- ...that has its "this" value set as this argument.
    

提交回复
热议问题