Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Bootstrap popover可用于html,但不能用于请求的网页_Javascript_Jquery_Html_Css_Twitter Bootstrap - Fatal编程技术网

Javascript Bootstrap popover可用于html,但不能用于请求的网页

Javascript Bootstrap popover可用于html,但不能用于请求的网页,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,我正在尝试开发一个jquery脚本,当您将鼠标悬停在一个表上时,它将打开一个包含网页的弹出窗口,当您离开它时,它将关闭。到目前为止,这是相当好的工作。我的密码是: var html = ""; var $that = ""; var $url = ""; $('td').hover(function() { var contents = $(this).html(); if (contents.match("^http")) { console.log('co

我正在尝试开发一个jquery脚本,当您将鼠标悬停在一个表上时,它将打开一个包含网页的弹出窗口,当您离开它时,它将关闭。到目前为止,这是相当好的工作。我的密码是:

var html = "";
var $that = "";
var $url = "";

$('td').hover(function() {
    var contents = $(this).html();

    if (contents.match("^http")) {
        console.log('contents', contents);
        $that = $(this);
        $url = contents;

        $.ajax({
            type: "POST",
            url: "/echo/html/",
            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) {
            console.log(' here is the html ' + html);


            html = '<ul class="nav"><li><a href="#">hola</li><li><a href="#">hola2</li></ul>';
            $link = $('<a href="myreference.html" class="p1" data-html="true" data-bind="popover">');
            $link.data('content', html);
            $(this).html($link);

            $that = $(this);

            // Trigger the popover to open
            $link = $(this).find('a');
            $link.popover("show");

        })
    };
}, function() {
    console.log('this2 ', $that);
    $link = $that.find('a');
    console.log('$link2 ', $link);
    $link.popover("hide");
    $that.html($url);
});           
var html=”“;
var$that=“”;
var$url=“”;
$('td')。悬停(函数(){
var contents=$(this.html();
if(contents.match(“^http”)){
console.log('contents',contents);
$that=$(this);
$url=内容;
$.ajax({
类型:“POST”,
url:“/echo/html/”,
背景:,即,
数据:{u:'http://stackoverflow.com'},
数据类型:“html”,
错误:函数(jqXHR、textStatus、errorshown){
console.log('error');
log(jqXHR、textStatus、errorshown);
}
}).done(函数(html){
log('hereisthehtml'+html);
html='
  • 通过ajax请求将网页插入popover时会出现问题。如果删除该行,您可以看到发生了什么:

    html = '<ul class="nav"><li><a href="#">hola</li><li><a href="#">hola2</li></ul>';
    
    html='
    • hola
    • hola2

    它不再工作了。我做错了什么?考虑到in中所有不可预测的js,是否有可能将整个网页加载到popover中?

    我认为这与js有关。如果你用以下方法过滤掉js:

    html = html.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
    
    html=html.replace(/]*>[\s\s]*?/gi',);
    
    它开始工作了