我想在没有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
中插入此表,我试图在追加中插入一个表标记,但它不起作用。
答案 0 :(得分:1)
如果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
才能追加任何内容。