我想从使用onkeypress事件的文本区域获取一个属性


I want to get an attribute from the textarea that uses the onkeypress event

我有以下代码:

<div>
    <form name="comentario" id="<?php echo $id?>" action="funcion_enviar_comentario.php" method="post">
        <input hidden="hidden" type="text" id="inputid" name="inputid" value="<?php echo $id?>">
        <textarea  class=estilotextarea1 id="comentario<?php echo $id?>" onkeypress="process1(event,this)" name="<?php echo $id?>" placeholder="Introduce tu comentario aquí..."></textarea>
        <script>
            function process1(e) {
              //var ide= document.getElementById("comentario <?php echo $id?>").name;
              //var submit= document.getElementById("enviado<?php echo $id?>").
              var code = (e.keyCode ? e.keyCode : e.which);
              if (code == 13) { 
                $('form#comentario<?php echo $id?>').submit();
               }
            }
        </script>
    </form>       
</div>

我希望函数process1从触发事件的文本区域中获取属性名称(这段代码在PHP while查询中),将其存储在一个变量中,这样我就可以使用该变量提交id与该变量匹配的表单。提前谢谢。

如果我理解正确,你可以使用这样的东西:

<div>
                <form name="comentario" id="1" action="funcion_enviar_comentario.php" method="post">
                <input hidden="hidden" type="text" id="inputid" name="inputid" value="1">
                <textarea  class=estilotextarea1 id="comentario1" onkeypress="process1(event,this.id)" name="1" placeholder="Introduce tu comentario aquí..."></textarea>
            </form>       
</div>
 <div>
                <form name="comentario" id="2" action="funcion_enviar_comentario.php" method="post">
                <input hidden="hidden" type="text" id="inputid" name="inputid" value="2">
                <textarea  class=estilotextarea1 id="comentario2" onkeypress="process1(event,this.id)" name="1" placeholder="Introduce tu comentario aquí..."></textarea>
            </form>       
</div>   

JQuery:

  function process1(e,id) {
          var code = (e.keyCode ? e.keyCode : e.which);
          if (code == 13) { 
                    alert('form #'+id);
           $('form #'+id).parent('form').submit();
            }
          }

因此,process1不应该在循环中,您可以通过将其作为参数传递给函数来轻松获取id。。。演示:http://jsfiddle.net/msgosoaL/1/

最后一行解释-你不能提交文本区域,所以你需要针对父窗体…