我正在尝试开发一个jquery脚本,它将打开一个弹出式窗口,其中包含网页时,你悬停在一个表td上,并关闭它,当你离开它。到目前为止,这一切都运行得很好。我的代码是:
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);
}); 您可以在以下位置查看它:
问题出现在通过ajax请求将网页插入到弹出窗口中。您可以看到如果删除该行会发生什么:
html = '<ul class="nav"><li><a href="#">hola</li><li><a href="#">hola2</li></ul>';它不再起作用。我做错了什么,有没有可能把一个完整的网页加载到弹出窗口中,因为里面有所有不可预测的js?
发布于 2015-01-31 04:16:46
我想这确实和js有关。如果您使用以下命令过滤出js:
html = html.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');它开始起作用了。
https://stackoverflow.com/questions/28202167
复制相似问题