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

前端 未结 5 910
余生分开走
余生分开走 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:18

    You can bind the context of the parent object like so.

    form.find(':radio').change(function(that) {
        var vacancy = $(this).attr('value');
        that.note.vacancy = vacancy;
    }.bind(null,this));
    

提交回复
热议问题