javascript - 类型错误 : context is undefined in javascript

标签 javascript jquery

我有以下代码:

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() {
   // ...
})

关于javascript - 类型错误 : context is undefined in javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28307558/

相关文章:

javascript - express-session 不会设置 cookie connect.sid

javascript - 更改范围 slider 颜色的最简单方法是什么?

javascript - 如果在输入字段中单击,则保持边栏打开

javascript - 切换时在 javascript 对象内递增

jquery - 如何让 jQuery 工具验证对一组单选按钮起作用?

javascript - 响应式地将文本输入内容对齐

php - 我应该选择 mysql 中的哪种数据类型来保存使用 PHP 的 javascript 代码?

jquery - 中心 flexslider 图像

javascript - Highcharts:当 useHTML 设置为 true 时,将点击事件附加到 dataLabel

javascript - 在 Sencha Touch 的面板中加载外部 HTML 文件