用于提交的textarea keyup事件

时间:2017-11-14 07:15:04

标签: javascript php html

在我的代码中,我有一个textarea,在用户输入任何内容后按Enter键然后需要执行一些代码,但如果用户按shift + enter,则新行只应出现在textarea中。以下是我目前的代码 -

<textarea id="commentarea<?php echo $row[slno]; ?>" class="secondtextareay pull-left" rows="2" cols="50" placeholder="Post comments here..." onkeyup="enter_comment(<?php echo $row['slno']; ?>,<?php echo $CUID; ?>);"></textarea>

<script type="text/javascript">
function enter_comment(postid,userpostedid) {
       if (event.which == 13) {
           document.getElementById('commentarea'+postid).value='';
           //insert_comment(id); // Call any function here: Just pass your actual Parameters to enter_comment().
       }
       else
       {
           return;
       }
}
</script>

现在,当我按下输入时,它工作正常,但如果我按shift + enter,那么它也是这样做的。我想防止这种情况,请帮助。

3 个答案:

答案 0 :(得分:1)

 if (event.keyCode == 13 && event.shiftKey) {
   // shift+enter pressed
 }
 else if(event.keyCode == 13){
          //enter key pressed
}else{
    //nothing
}

答案 1 :(得分:0)

您可以通过function enter_comment(postid,userpostedid) { if (event.which == 13 && !event.shiftKey) { document.getElementById('commentarea'+postid).value=''; //insert_comment(id); // Call any function here: Just pass your actual Parameters to enter_comment(). } else if (event.which == 13 && event.shiftKey) { // Create the new line. } else { return; } } 属性检查是否按下了shift键。因此,您的事件处理程序可以修改为:

Exception in thread Thread-16923:

Traceback (most recent call last):

  File "/home/aryan/miniconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner

    self.run()

  File "/home/aryan/miniconda2/lib/python2.7/threading.py", line 754, in run

    self.__target(*self.__args, **self.__kwargs)


  File "/home/aryan/miniconda2/lib/python2.7/site-packages/tflearn
/data_flow.py", line 240, in wait_for_threads

    self.coord.join(self.threads)

  File "/home/aryan/miniconda2/lib/python2.7/site-packages/tensorflow/python
/training/coordinator.py", line 397, in join
    " ".join(stragglers))

"RuntimeError: Coordinator stopped with threads still running: Thread-16922"

答案 2 :(得分:0)

最好使用// oldList is your list containing 15 items adapter.SetMessages(new List(oldList.GetRange(0, 4))); recyclerView.NotifyDataSetChanged();

  密钥关闭时会触发

onkeydown

而不是onkeydown

  释放密钥时会触发 onkeyup

您可以onkeyup

按下shift键
event.shiftKey(true/false)
相关问题