2014-03-28 40 views
0

您好,所以我有一个textrea,当用户插入它会显示在iframe中的数据,我想我已经走了这么远,现在的代码:努力的textarea复制到IFRAME

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Untitled 1</title> 
</head> 
<?php 
    if (isset($_POST["preveri"])) 
    { 
    $koda = $_POST["koda"]; 
    $fp = fopen('C:\inetpub\wwwroot\tutorial\koda.php'); 
    fwrite($fp, '$koda'); 
    fclose($fp); 
    } 
?> 
<body> 
    <table style="width: 841px; height: 511px"> 
    <tr> 
     <td valign="top"> 
      <form method="post" action="tutorial.php"> 
       <textarea name="koda" cols="50" rows="30"></textarea> 
       <p><input name="preveri" type="submit" value="Preveri" /></p> 
      </form> 
     </td> 
     <td valign="top"> 
      <iframe src="koda.php" width="450px" height="470px"></iframe> 
     </td> 
    </tr> 
    </table> 
</body> 

</html> 
+0

它看起来像某种预演。这有什么好处,而不是显示它到一些div?如果需要进行一些修改(如BBCode> HTML),AJAX可以提供帮助。 –

+0

它将用于HTML代码,所以如果用户输入一个html代码,它将显示它将如何显示 – user3472359

+0

好吧,如果你将HTML从textarea放入div,它也会被解释。 –

回答

1

使用DIV而不是一个iframe。

div.innerHTML=user_text; 

它会自动解释并显示为html,而不是文本。

0

我在我的一个项目中使用了JavaScript。

<form> 
    ... 
    <textarea name="message"></textarea> 
    <input type="button" value="Preview" onclick="displayHTML(this.form)"> 
    ... 
</form> 

与JS:

function displayHTML(form) 
{ 
    var html = form.message.value; 
    win = window.open("about:blank", "Preview", "toolbar = no, status = no"); 
    win.document.write("" + html + ""); 
} 
0

使用正常的div,如果你想用PHP 访问,如果ü可以使用JavaScript与jQuery添加

<iframe id="iframe"> 

<script> 
text = $("textarea").val(); 
$("#iframe your input tag").append(text); 
</script>