TypeError:上下文在javascript中未定义

TypeError: context is undefined in javascript

本文关键字:未定义 javascript 上下文 TypeError      更新时间:2023-09-26

我有以下代码:

function pop_open () {
    var contents = $( this ).html() ;
            if (contents.match("^http")) {
                console.log('contents',contents);
                $that = $( this );
                $url = contents;
                $.ajax({
                        type:"POST",
                        url: "Ajax/getHtml",
                        context: $that,
                        data: { u : 'http://stackoverflow.com' },
                        dataType: 'html',    
                        error: function(jqXHR, textStatus, errorThrown) {
                            console.log('error');
                            console.log(jqXHR, textStatus, errorThrown);
                        }
                    }).done(function(html) {
                      $link = $('<a href="myreference.html" class="p1" data-html="true" data-bind="popover">');
                    $link.data('content', html);
            $that = $(this);
          // Trigger the popover to open
            $link = $(this).find('a');
            $link.popover("show");
                   });
        }
}
$('td').hover( pop_open(), function() {
            $link = $that.find('a');
            $link.popover("hide");
           $that.html($url);
        });  

我在标题中收到错误。我做错了什么?

调用函数pop_open()但需要传递对函数pop_open的引用

$('td').hover(pop_open, function() {
   // ...
})