Javascript Jquery未将html传递给iframe

Javascript Jquery未将html传递给iframe,javascript,php,jquery,html,mysql,Javascript,Php,Jquery,Html,Mysql,我已经在这方面工作了很多年,但我一辈子都无法理解我做错了什么 因此,我的JQuery正在工作,我知道这是一个简单的隐藏/显示脚本。我没有在控制台中记录任何错误,但我尝试做的是: 我有一个页面,允许我创建一个帖子,我建立了一个小的WYSIWYG编辑器来美化帖子-它工作正常,并以HTML的形式将帖子输入数据库,我可以引用它,它会如预期的那样显示出来。我想做的是,它有一个“编辑帖子”页面,看起来几乎一样,但当你访问帖子时,它会显示帖子标题和帖子正文,使用相同的WYSIWYG编辑器,但已经包含了帖子内容

我已经在这方面工作了很多年,但我一辈子都无法理解我做错了什么

因此,我的JQuery正在工作,我知道这是一个简单的隐藏/显示脚本。我没有在控制台中记录任何错误,但我尝试做的是:

我有一个页面,允许我创建一个帖子,我建立了一个小的WYSIWYG编辑器来美化帖子-它工作正常,并以HTML的形式将帖子输入数据库,我可以引用它,它会如预期的那样显示出来。我想做的是,它有一个“编辑帖子”页面,看起来几乎一样,但当你访问帖子时,它会显示帖子标题和帖子正文,使用相同的WYSIWYG编辑器,但已经包含了帖子内容。我希望这有意义,以下是我的文件:

创建post文件:

<?php

if(isset($_POST["submit"])){
$hostname='localhost';
$username='******';
$password='******';

try {

$dbh = new PDO("mysql:host=$hostname;dbname=******",$username,$password);

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line

$sql = "INSERT INTO doc_list (doc_title, doc_content, doc_created) VALUES ('".$_POST["doc_title"]."','".$_POST["doc_content"]."', NOW() )";


if ($dbh->query($sql)) {
    header ('Location: ../docList.php');
}
else{
}

$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}

}
?>

<form action="actions/newDocAdd.php" method="post" id="rtf" name="">
    <input type="text" name="doc_title" id="doc_title" required="required" placeholder="Document Title"/><br />



    <button class="postEditBtn" type="button" onclick="bold()" title="Bold Text"><i class="fa fa-bold"></i></button>
    <button class="postEditBtn" type="button" onclick="italic()" title="Italic Text"><i class="fa fa-italic"></i></button>
    <button class="postEditBtn" type="button" onclick="underline()" title="Underline Text"><i class="fa fa-underline"></i></button>
    <button class="postEditBtn" type="button" onclick="fontName()" title="Font Family"><i class="fa fa-font"></i></button>
    <button class="postEditBtn" type="button" onclick="fontsize()" title="Font Size"><i class="fa fa-text-height"></i></button>
    <button class="postEditBtn" type="button" onclick="fontcolor()" title="Font Colour"><i class="fa fa-eraser"></i></button>
    <button class="postEditBtn" type="button" onclick="hiliteColor()" title="Highlight Text"><i class="fa fa-magic"></i></button>
    <button class="postEditBtn" type="button" onclick="link()" title="Add/Edit Link"><i class="fa fa-link"></i></button>
    <button class="postEditBtn" type="button" onclick="unlink()" title="Remove Link"><i class="fa fa-chain-broken"></i></button>
    <button class="postEditBtn" type="button" onclick="justifyLeft()" title="Text align-left"><i class="fa fa-align-left"></i></button>
    <button class="postEditBtn" type="button" onclick="justifyCenter()" title="Text align-center"><i class="fa fa-align-center"></i></button>
    <button class="postEditBtn" type="button" onclick="justifyRight()" title="Text align-right"><i class="fa fa-align-right"></i></button>

    <br><br>

    <textarea name="doc_content" id="doc_content" placeholder="Document Content" style="display: none;"></textarea>
    <iframe name="editor" id="editor" style="width:100%; height: auto;"></iframe>

    <br><br> 
    <input onclick="formsubmit()" type="submit" value="Create Document" name="submit"/><br />
    <input type"myBtn" type="button" value="Create document" onClick="javascript:submit_form();" />


</form>

所以我把一切都弄明白了-我做了一些简单的JS

<script>
var iframe = document.getElementById('editor'),
    iframedoc = iframe.contentDocument || iframe.contentWindow.document;

    iframedoc.body.innerHTML = '<?php echo $doc['doc_content']; ?> ';

</script>

var iframe=document.getElementById('editor'),
iframedoc=iframe.contentDocument | | iframe.contentWindow.document;
iframedoc.body.innerHTML='';

它通过ID将iframe作为目标,然后允许我也对其进行编辑,并在我返回时保留更改。

嘿,文本编辑的东西不是我,而是来自我的WYSIWYG编辑器,它是页面源你不应该给多个元素相同的ID,这就是类的用途。给div一个唯一的id,在JavaScript代码中选择该id,然后看看它是否有用。
    <textarea name="doc_content" id="doc_content" placeholder="Document Content" style="display: none;"></textarea>
    <iframe name="editor" id="editor" style="width:100%; height: auto;" ></iframe>

   <div id="editor"></div>

<script>
$(document).ready(function (){
    $("#editor").html("<div style="text-align: center;">dsffffsfsfsfsdf</div>");
})
</script>
<script>
var iframe = document.getElementById('editor'),
    iframedoc = iframe.contentDocument || iframe.contentWindow.document;

    iframedoc.body.innerHTML = '<?php echo $doc['doc_content']; ?> ';

</script>