如何在连续的textarea中打印结果?

时间:2013-07-10 06:32:17

标签: 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 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>

和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";
       }
  }

当我运行此代码时,它的工作正常也给我输出。但我的问题是输出只打印在一个textarea中。我想在连续的textarea中打印输出。

code.js中的此代码打印输出。

p5pkg.CORE.print = function(List__) {
    var i;
    for (i = 0; i < List__.length; i++) {
       document.getElementById('print-result').value += p5str(List__[i])                    
    }
}

所以我需要做的就是连续textarea打印我的输出。请帮助我。

2 个答案:

答案 0 :(得分:0)

name attribute添加到您的textarea

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

取代

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

<强>更新

在您的代码中,我看不到textarea name="code",而您正在使用它。 是codeguru吗?

答案 1 :(得分:0)

对页面中的不同元素使用相同的id会产生问题.. 使文本区域像这样..

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

打印输出的code.js中的修改代码是

       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;
        }