我想在没有 iframe 的情况下插入这段代码:
我有以下 HTML
和 JQUERY
代码,它工作得很好:
$('#info').append('<h3>' + 'Sectores de la comuna de Curicó' + '</h3>' +
'<table id="sectoresTableID" class="table table-hover table-condensed" style="width:99%">' +
'<head>' +
'<tr>' +
'<th>Número</th>' +
'<th>Sector</th>' +
'</tr>' +
'</head>' +
'<body>' +
'</body>' +
'</table>');
但是现在,我想将此表插入到 Iframe
中,我尝试在 Append 中插入表标记,但它不起作用。
最佳答案
如果 iframe 与您的域位于不同的域中,则很可能不可能,除非 iframe 内容明确授予权限。如果iframe在同一个域中,你可以这样做。
$(document.getElementById("iframeID").contentDocument.body).append('<h3>' + 'Sectores de la comuna de Curicó' + '</h3>' +
'<table id="sectoresTableID" class="table table-hover table-condensed" style="width:99%">' +
'<head>' +
'<tr>' +
'<th>Número</th>' +
'<th>Sector</th>' +
'</tr>' +
'</head>' +
'<body>' +
'</body>' +
'</table>');
这里的技巧是,您必须先访问 contentDocument
,然后才能附加任何内容。
关于javascript - 如何在 iframe 中插入表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28787791/