当我单击一个按钮时,我试图在 iframe 中插入一个表格,但在方法 "pasteHTML" 中出现错误。这是我写的代码:
<html>
<body>
<input type = "button" onClick="setContent()" value="getContent"></input>
<iframe id = "iframe" border="0" >
</iframe>
<script type="text/javascript">
var iframe = document.getElementById('iframe');
iframe.contentDocument.designMode = "on";
function setContent()
{
var iframe = document.getElementById('iframe');
var str = "<table><tr><td>dushyanth</td></tr></table>";
var sel = iframe.document.selection.createRange();
sel.pasteHTML(str);
sel.select();
}
</script>