Php 如何在连续的文本区域中打印结果?

Php 如何在连续的文本区域中打印结果?,php,javascript,jquery,html,asp.net,Php,Javascript,Jquery,Html,Asp.net,我再次来到这里是为了同样的问题 现在我的老问题解决了。我有两个文件index.html和code.js 1) index.html <html> <head> <title> perl </title> <link rel="stylesheet" href="http://code.guru99.com/css/1140.css" type="text/css" media="screen" /> <link r

我再次来到这里是为了同样的问题

现在我的老问题解决了。我有两个文件index.html和code.js 1) index.html

<html>
<head>
<title> perl </title>
<link rel="stylesheet" href="http://code.guru99.com/css/1140.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="http://code.guru99.com/css/styles.css" type="text/css" media="screen" />
        <script src="http://code.guru99.com/php/lib/codemirror.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">></script>
        <link rel="stylesheet" href="http://code.guru99.com/Sanjay/lib/codemirror.css" type="text/css" media="screen" />
        <script src="code.js"></script>
        <script type="text/javascript" src="http://code.guru99.com/perl/perl.js"></script>
<style> 
 .CodeMirror {
    border: 1px solid #eee;
    height: auto;
    width : 600px;
}
.CodeMirror-scroll {
    height: auto;
    overflow-y: hidden;
    overflow-x: auto;
}
</style>
</head>
<body>
Integer : whole numbers e.g. -3, 0, 69. The maximum value of an integer is platform-dependent. On a 32 bit machine, its usually around 2 billion. 64 bit machines usually have larger values. The constant PHP_INT_MAX is used to determine the maximum value.
<pre class="codeguru">say 'hi';</pre>
Let us now look at how PHP determines the data type depending on the attributes of the supplied data.
<pre class="codeguru">say 'hello';</pre>
Floating point numbers
<pre class="codeguru">say 'you r amazing';</pre>
Character strings
<pre class="codeguru">say 'i am fine';</pre>
</div>
<form class="hidden code-box" method="GET" name="sample">
<div dir="ltr"><textarea class="php" name="codeguru"></textarea></div>
<input type="button" value="Run" />
</br></br>
Output:</br></br>
    <textarea id="print-result" disabled="true" cols="77"></textarea></br>
</form></div>
</body>
</html>

perl
>
.CodeMirror{
边框:1px实心#eee;
高度:自动;
宽度:600px;
}
.CodeMirror滚动条{
高度:自动;
溢出y:隐藏;
溢出-x:自动;
}
整数:整数,例如-3、0、69。整数的最大值取决于平台。在32位机器上,它通常大约是20亿。64位机器通常具有较大的值。常量PHP_INT_MAX用于确定最大值。
说“嗨”;
现在让我们看看PHP如何根据所提供数据的属性确定数据类型。
说‘你好’;
浮点数
说“你太棒了”;
字符串
说‘我很好’;


输出:


和code.js包含以下代码

$(document).ready(function() 
{
    $('pre.codeguru').each(function() 
    {
            var pre = this;
            var form = $('form[name=sample]').clone();
            $(form).removeAttr('name');
            $(form).removeClass('hidden');
            $($(form).find('textarea')[0]).val($(pre).text());
            var id = $(pre).attr('id');
            $(form).find('div textarea[name=code]').first().attr('id', id);
        $(pre).replaceWith(form);
    });


    var n = 0;
    $('input[type=button]').each(function () {
            $(this).click(function (x) {
                return function () {
                    execute(x);
                };
            }(n++))
        }
    );

    window.editors = [];
    $('textarea[name=codeguru]').each(function() 
    {
        window.editor = CodeMirror.fromTextArea(this, 
        {
            lineNumbers: true,
            matchBrackets: true,
            mode: "application/x-httpd-perl",
            tabMode: "shift"
         });
            editors.push(editor);
    });



});
function execute(idx) {
      p5pkg.CORE.print = function(List__) {
          var i;
          for (i = 0; i < List__.length; i++) {
            document.getElementById('print-result').value+=p5str(List__[i])        
          }
          return true;
      };
      p5pkg["main"]["v_^O"] = "browser";
      p5pkg["main"]["Hash_INC"]["Perlito5/strict.pm"] = "Perlito5/strict.pm";
      p5pkg["main"]["Hash_INC"]["Perlito5/warnings.pm"] = "Perlito5/warnings.pm";

      var source = editors[idx].getValue();
      alert(source);

      var pos = 0;
      var ast;
      var match;
      document.getElementById('print-result').value = "";
      try {
            var start = new Date().getTime();
            var js_source = p5pkg["Perlito5"].compile_p5_to_js([source]);
            var end = new Date().getTime();
            var time = end - start;
            // run
            start = new Date().getTime();
            eval(js_source);
            end = new Date().getTime();
            time = end - start;
       }
       catch(err) {
            //document.getElementById('log-result').value += "Error:\n";
       }
  }
$(文档).ready(函数()
{
$('pre.codeguru')。每个(函数()
{
var pre=此;
var form=$('form[name=sample]')。clone();
$(form.removeAttr('name');
$(form).removeClass('hidden');
$($(form.find('textarea')[0]).val($(pre.text());
var id=$(pre.attr('id');
$(form).find('div textarea[name=code]')).first().attr('id',id);
$(预)。替换为(表格);
});
var n=0;
$('input[type=button]')。每个(函数(){
$(此)。单击(函数(x){
返回函数(){
执行(x);
};
}(n++)
}
);
window.editors=[];
$('textarea[name=codeguru]')。每个(函数()
{
window.editor=CodeMirror.fromTextArea(此,
{
行号:对,
是的,
模式:“应用程序/x-httpd-perl”,
tabMode:“移位”
});
编辑器。推送(编辑器);
});
});
函数执行(idx){
p5pkg.CORE.print=函数(列表){
var i;
对于(i=0;i<列表长度;i++){
document.getElementById('print-result')。value+=p5str(List\uui])
}
返回true;
};
p5pkg[“main”][“v_^O”]=“browser”;
p5pkg[“main”][“Hash_INC”][“Perlito5/strict.pm”]=“Perlito5/strict.pm”;
p5pkg[“main”][“Hash_INC”][“Perlito5/warnings.pm”]=“Perlito5/warnings.pm”;
var source=editors[idx].getValue();
警报(来源);
var-pos=0;
var-ast;
var匹配;
document.getElementById('print-result')。value=“”;
试一试{
var start=new Date().getTime();
var js_source=p5pkg[“Perlito5”]。将_p5_编译为_js([source]);
var end=new Date().getTime();
var时间=结束-开始;
//跑
开始=新日期().getTime();
评估(js_来源);
end=新日期().getTime();
时间=结束-开始;
}
捕捉(错误){
//document.getElementById('log-result')。值+=“错误:\n”;
}
}
当我运行这段代码时,它可以很好地工作,并给我输出。但我的问题是输出只在一个文本区域打印。我想在连续的文本区域打印输出

code.js中的这段代码打印输出

p5pkg.CORE.print = function(List__) {
    var i;
    for (i = 0; i < List__.length; i++) {
       document.getElementById('print-result').value += p5str(List__[i])                    
    }
}
p5pkg.CORE.print=函数(列表){
var i;
对于(i=0;i<列表长度;i++){
document.getElementById('print-result')。value+=p5str(List\uui])
}
}

因此,我必须在连续的文本区域中打印输出。请帮助我。

名称属性添加到
文本区域中

<textarea id="print-result" disabled="true" name="code" cols="77"></textarea>

代替

<textarea id="print-result" disabled="true" cols="77"></textarea>

已更新

在你的代码中,我看不到一个
textarea
name=“code”
,而你正在使用它。
是不是
codeguru

对页面中的不同元素使用相同的id会产生问题。。 使文本区域如下所示

<textarea id="print-result" class='print-result' disabled="true" cols="77></textarea>

创建textarea并将其值设置为。首先取消读取questino@DevZer0你说在连续的文本区域中打印我的输出应该有一个文本区域…是的,或者是从html静态呈现,或者是用jsi动态创建的,我已经读到了这个关键字可以完成的地方。有人能告诉我在这个特殊的例子中这是如何传递的吗?Bro codeguru是一个pre-tag类。在code.js的帮助下,pre标记被textarea替换,所以我正在使用codegurui,我已经读到了这个关键字可以实现的地方。有人能告诉我,在这个特殊的例子中,这是如何通过的吗
       p5pkg.CORE.print = function(List__) {
            var i,concat='';
            for (i = 0; i < List__.length; i++) {
            concat=$(".print-result").eq(idx).val();
            $(".print-result").eq(idx).val(concat+p5str(List__[i]));

       }
            return true;
        }