jQuery:改变iframe内容

oka*_*56k 0 iframe jquery wysihtml5

据我所知,这段代码应该可行,但事实并非如此,而且我完全难过了.有什么想法吗?

jQuery的

$('.article_chooser').click(function() {
    var src = $(this).attr('value');
$("#doc_edits_attributes_0_body").parent("iframe html body").html($("#article"+src).html());
console.log($("#doc_edits_attributes_0_body").parent("iframe html body").html());
});
Run Code Online (Sandbox Code Playgroud)

HTML

<textarea class="editable_areas" cols="40" id="doc_edits_attributes_0_body" name="doc[edits_attributes][0][body]" rows="20" style="display: none;"></textarea>
<iframe class="wysihtml5-sandbox" security="restricted" allowtransparency="true" frameborder="0" width="0" height="0" marginwidth="0" marginheight="0">
    <html>
        <body marginwidth="0" marginheight="0" contenteditable="true" class="editable_areas wysihtml5-editor" spellcheck="true">
        </body>
    </html>
</iframe>
Run Code Online (Sandbox Code Playgroud)

干杯!

Nic*_*che 9

要编辑iframe的内容,您必须body在iframe中调用标记:

<iframe class="wysihtml5-sandbox" security="restricted" allowtransparency="true" frameborder="0" width="0" height="0" marginwidth="0" marginheight="0" id="iframe">
    <html>
        <body marginwidth="0" marginheight="0" contenteditable="true" class="editable_areas wysihtml5-editor" spellcheck="true">
        </body>
    </html>
</iframe>

<script type="text/javascript">
$(document).ready(function() {
    $('#iframe').contents().find('body').html('New Content');
});
</script>
Run Code Online (Sandbox Code Playgroud)